datetime-offset.js
Javascript Class like C# DateTimeOffset Structure (mapping momnet-timezome)
Default Usage
;// if using Require// const DateTimeOffset = require('datetime-offset').default const t1 = ;const t2 = '2017-04-10 00:00:00' format: 'YYYY-MM-DD HH:mm:ss' // default timezone UTCconst t3 = '2017-04-10 00:00:00' format: 'YYYY-MM-DD HH:mm:ss' timezone: 'UTC' // same 'GMT', 'Atlantic/Reykjavik'const t4 = '2017-04-10 09:00:00' format: 'YYYY-MM-DD HH:mm:ss' timezone: 'KST' // same 'UTC+9', 'Asia/Seoul';
Supported Timezones
-
UTC (Same GMT, Atlantic/Reykjavik)
-
KST (Smae UTC+9, Asia/Seoul)
-
EDT (Same UTC-4, America/New_York)
-
PDT (Same UTC-7, America/Vancouver)
-
JST (Same UTC+9, Asia/Tokyo)
-
CST (Smae UTC+8, Asia/Shanghai)
-
If you have a timezone you need, please add it to
timezone-consts.js
using http://momentjs.com/timezone.
Constructor
DateTimeOffset(datetime, options)
;
- date : Supported ISO 8601 strings #, if you using custom fomarts, refer
ptions.format
- options : object
- format : refer http://momentjs.com/docs/#/parsing/string-format/
- timezone : refer Supported Timezones
Methods
toString(format = 'YYYY-MM-DD HH:mm:ss', timezone = 'GMT')
- The order of the
format
andtimezone
parameters has changed since version 0.3.0. - Default
format
: YYYY-MM-DD HH:mm:ss - Default
timezone
: GMT
const t2 = '2017-04-10';console // Atlantic/Reykjavikt2 // 2017-04-10 00:00:00t2 // 2017-04-10 00:00:00t2 // 2017-04-10 09:00:00t2 // 2017-04-10t2 // 2017-04-10 timezone default set 'UTC' const t4 = '2017-04-10 09:00:00' format: 'YYYY-MM-DD HH:mm:ss' timezone: 'KST';console // Asia/Seoult4 // 2017-04-10 00:00:00t4 // 2017-04-10 00:00:00t4 // 2017-04-10 09:00:00t4 // 2017-04-10t4 // 2017-04-10 timezone default set 'UTC'
addYears(number)
const t = '2017-04-10';console // 2027-04-10 00:00:00console // 2007-04-10 00:00:00t // throw Errort // throw Errort // throw Errort // throw Error
addMonth(number)
const t = '2017-04-10';console // 2017-09-10 00:00:00console // 2019-09-10 00:00:00console // 2019-02-10 00:00:00console // 2018-02-10 00:00:00t // throw Errort // throw Errort // throw Errort // throw Error
addDays(number)
const t = '2017-04-10';console; // 2017-04-20 00:00:00console; // 2017-04-15 00:00:00t // throw Errort // throw Errort // throw Errort // throw Error
addHours(number)
const t = '2017-04-10';console // 2017-04-10 10:00:00console // 2017-04-11 00:00:00console // 2017-04-10 14:00:00t // throw Errort // throw Errort // throw Errort // throw Error
addMinutes(number)
const t = '2017-04-10';console // 2017-04-10 00:10:00console // 2017-04-00 01:10:00console // 2017-04-09 23:00:00t // throw Errort // throw Errort // throw Errort // throw Error
addSeconds(number)
const t = '2017-04-10';console // 2017-04-10 00:00:10console // 2017-04-10 00:01:10console // 2017-04-09 23:59:00t // throw Errort // throw Errort // throw Errort // throw Error
compareTo(DateTimeOffset)
- Compares to DateTimeOffset and returns the subtracted value
const customTime = '2017-04-10T00:00:00Z';const customTime2 = '2017-04-09T23:50:00Z';const customTime3 = '2017-04-10T00:10:00Z'; const t = customTime;const t2 = customTime2;const t3 = customTime3; console; // 0console; // 600000console; // -600000 t; // throw Errort; // throw Errort; // throw Errort; // throw Error
equals(DateTimeOffset)
- To be developed
static compare(DateTimeOffset, DateTimeOffset)
- To be developed p
static equals(DateTimeOffset, DateTimeOffset)
- To be developed