@@ -36,6 +36,7 @@ The `Dayjs` object is immutable, that is, all API operations that change the `Da
36
36
- [ Difference ` .diff(compared: Dayjs, unit: string (default: 'milliseconds'), float?: boolean) ` ] ( #difference-diffcompared-dayjs-unit-string-default-milliseconds-float-boolean )
37
37
- [ Unix Timestamp (milliseconds) ` .valueOf() ` ] ( #unix-timestamp-milliseconds-valueof )
38
38
- [ Unix Timestamp (seconds) ` .unix() ` ] ( #unix-timestamp-seconds-unix )
39
+ - [ UTC offset (minutes) ` .utcOffset() ` ] ( #utc-offset-minutes-utcoffset )
39
40
- [ Days in the Month ` .daysInMonth() ` ] ( #days-in-the-month-daysinmonth )
40
41
- [ As Javascript Date ` .toDate() ` ] ( #as-javascript-date-todate )
41
42
- [ As Array ` .toArray() ` ] ( #as-array-toarray )
@@ -72,7 +73,7 @@ Day.js also parses other date formats.
72
73
#### [ ISO 8601] ( https://en.wikipedia.org/wiki/ISO_8601 ) string
73
74
74
75
``` js
75
- dayjs (' 2018-04-04T16:00:00.000Z' );
76
+ dayjs (" 2018-04-04T16:00:00.000Z" );
76
77
```
77
78
78
79
#### Native Javascript Date object
@@ -99,15 +100,16 @@ dayjs.unix(1318781876.721);
99
100
```
100
101
101
102
### Custom Parse Format
102
- * parse custom formats ` dayjs("12-25-1995", "MM-DD-YYYY") ` in plugin [ ` CustomParseFormat ` ] ( ./Plugin.md#customparseformat )
103
+
104
+ - parse custom formats ` dayjs("12-25-1995", "MM-DD-YYYY") ` in plugin [ ` CustomParseFormat ` ] ( ./Plugin.md#customparseformat )
103
105
104
106
### Clone ` .clone() | dayjs(original: Dayjs) `
105
107
106
108
Returns a cloned ` Dayjs ` .
107
109
108
110
``` js
109
111
dayjs ().clone ();
110
- dayjs (dayjs (' 2019-01-25' )); // passing a Dayjs object to a constructor will also clone it
112
+ dayjs (dayjs (" 2019-01-25" )); // passing a Dayjs object to a constructor will also clone it
111
113
```
112
114
113
115
### Validation ` .isValid() `
@@ -189,9 +191,9 @@ dayjs().millisecond();
189
191
Returns a ` Dayjs ` with the applied changes.
190
192
191
193
``` js
192
- dayjs ().set (' date' , 1 );
193
- dayjs ().set (' month' , 3 ); // April
194
- dayjs ().set (' second' , 30 );
194
+ dayjs ().set (" date" , 1 );
195
+ dayjs ().set (" month" , 3 ); // April
196
+ dayjs ().set (" second" , 30 );
195
197
```
196
198
197
199
#### List of all available units
@@ -212,41 +214,42 @@ dayjs().set('second', 30);
212
214
` Dayjs ` objects can be manipulated in many ways.
213
215
214
216
``` js
215
- dayjs (' 2019-01-25' )
216
- .add (1 , ' day' )
217
- .subtract (1 , ' year' ).toString (); // Fri, 26 Jan 2018 00:00:00 GMT
217
+ dayjs (" 2019-01-25" )
218
+ .add (1 , " day" )
219
+ .subtract (1 , " year" )
220
+ .toString (); // Fri, 26 Jan 2018 00:00:00 GMT
218
221
```
219
222
220
223
### Add ` .add(value: number, unit: string) `
221
224
222
225
Returns a cloned ` Dayjs ` with a specified amount of time added.
223
226
224
227
``` js
225
- dayjs ().add (7 , ' day' );
228
+ dayjs ().add (7 , " day" );
226
229
```
227
230
228
231
### Subtract ` .subtract(value: number, unit: string) `
229
232
230
233
Returns a cloned ` Dayjs ` with a specified amount of time subtracted.
231
234
232
235
``` js
233
- dayjs ().subtract (7 , ' year' );
236
+ dayjs ().subtract (7 , " year" );
234
237
```
235
238
236
239
### Start of Time ` .startOf(unit: string) `
237
240
238
241
Returns a cloned ` Dayjs ` set to the start of the specified unit of time.
239
242
240
243
``` js
241
- dayjs ().startOf (' week' );
244
+ dayjs ().startOf (" week" );
242
245
```
243
246
244
247
### End of Time ` .endOf(unit: string) `
245
248
246
249
Returns a cloned ` Dayjs ` set to the end of the specified unit of time.
247
250
248
251
``` js
249
- dayjs ().endOf (' month' );
252
+ dayjs ().endOf (" month" );
250
253
```
251
254
252
255
## Displaying
@@ -259,9 +262,9 @@ To escape characters, wrap them in square or curly brackets (e.g. `[G] {um}`).
259
262
``` js
260
263
dayjs ().format (); // current date in ISO6801, without fraction seconds e.g. '2020-04-02T08:02:17-05:00'
261
264
262
- dayjs (' 2019-01-25' ).format (' {YYYY} MM-DDTHH:mm:ssZ[Z]' ); // '{2019} 01-25T00:00:00-02:00Z'
265
+ dayjs (" 2019-01-25" ).format (" {YYYY} MM-DDTHH:mm:ssZ[Z]" ); // '{2019} 01-25T00:00:00-02:00Z'
263
266
264
- dayjs (' 2019-01-25' ).format (' DD/MM/YYYY' ); // '25/01/2019'
267
+ dayjs (" 2019-01-25" ).format (" DD/MM/YYYY" ); // '25/01/2019'
265
268
```
266
269
267
270
#### List of all available formats
@@ -294,84 +297,92 @@ dayjs('2019-01-25').format('DD/MM/YYYY'); // '25/01/2019'
294
297
| ` A ` | AM PM | |
295
298
| ` a ` | am pm | |
296
299
297
- * More available formats ` Q Do k kk X x ... ` in plugin [ ` AdvancedFormat ` ] ( ./Plugin.md#advancedformat )
298
- * Localized format options ` L LT LTS ... ` in plugin [ ` LocalizedFormat ` ] ( ./Plugin.md#localizedFormat )
300
+ - More available formats ` Q Do k kk X x ... ` in plugin [ ` AdvancedFormat ` ] ( ./Plugin.md#advancedformat )
301
+ - Localized format options ` L LT LTS ... ` in plugin [ ` LocalizedFormat ` ] ( ./Plugin.md#localizedFormat )
299
302
300
303
### Difference ` .diff(compared: Dayjs, unit: string (default: 'milliseconds'), float?: boolean) `
301
304
302
305
Returns a ` number ` indicating the difference of two ` Dayjs ` s in the specified unit.
303
306
304
307
``` js
305
- const date1 = dayjs (' 2019-01-25' );
306
- const date2 = dayjs (' 2018-06-05' );
308
+ const date1 = dayjs (" 2019-01-25" );
309
+ const date2 = dayjs (" 2018-06-05" );
307
310
date1 .diff (date2); // 20214000000
308
- date1 .diff (date2, ' month' ); // 7
309
- date1 .diff (date2, ' month' , true ); // 7.645161290322581
310
- date1 .diff (date2, ' day' ); // 233
311
+ date1 .diff (date2, " month" ); // 7
312
+ date1 .diff (date2, " month" , true ); // 7.645161290322581
313
+ date1 .diff (date2, " day" ); // 233
311
314
```
312
315
313
316
### Unix Timestamp (milliseconds) ` .valueOf() `
314
317
315
318
Returns the ` number ` of milliseconds since the Unix Epoch for the ` Dayjs ` .
316
319
317
320
``` js
318
- dayjs (' 2019-01-25' ).valueOf (); // 1548381600000
321
+ dayjs (" 2019-01-25" ).valueOf (); // 1548381600000
319
322
```
320
323
321
324
### Unix Timestamp (seconds) ` .unix() `
322
325
323
326
Returns the ` number ` of seconds since the Unix Epoch for the ` Dayjs ` .
324
327
325
328
``` js
326
- dayjs (' 2019-01-25' ).unix (); // 1548381600
329
+ dayjs (" 2019-01-25" ).unix (); // 1548381600
330
+ ```
331
+
332
+ ### UTC Offset (minutes) ` .utcOffset() `
333
+
334
+ Returns the UTC offset in minutes for the ` Dayjs ` .
335
+
336
+ ``` js
337
+ dayjs (" 2013-03-07T07:00:00+08:00" ).utcOffset (); // 60
327
338
```
328
339
329
340
### Days in the Month ` .daysInMonth() `
330
341
331
342
Returns the ` number ` of days in the ` Dayjs ` 's month.
332
343
333
344
``` js
334
- dayjs (' 2019-01-25' ).daysInMonth (); // 31
345
+ dayjs (" 2019-01-25" ).daysInMonth (); // 31
335
346
```
336
347
337
348
### As Javascript Date ` .toDate() `
338
349
339
350
Returns a copy of the native ` Date ` object parsed from the ` Dayjs ` object.
340
351
341
352
``` js
342
- dayjs (' 2019-01-25' ).toDate ();
353
+ dayjs (" 2019-01-25" ).toDate ();
343
354
```
344
355
345
356
### As Array ` .toArray() `
346
357
347
358
Returns an ` array ` that mirrors the parameters from new Date().
348
359
349
360
``` js
350
- dayjs (' 2019-01-25' ).toArray (); // [ 2019, 0, 25, 0, 0, 0, 0 ]
361
+ dayjs (" 2019-01-25" ).toArray (); // [ 2019, 0, 25, 0, 0, 0, 0 ]
351
362
```
352
363
353
364
### As JSON ` .toJSON() `
354
365
355
366
Returns the ` Dayjs ` formatted in an ISO8601 ` string ` .
356
367
357
368
``` js
358
- dayjs (' 2019-01-25' ).toJSON (); // '2019-01-25T02:00:00.000Z'
369
+ dayjs (" 2019-01-25" ).toJSON (); // '2019-01-25T02:00:00.000Z'
359
370
```
360
371
361
372
### As ISO 8601 String ` .toISOString() `
362
373
363
374
Returns the ` Dayjs ` formatted in an ISO8601 ` string ` .
364
375
365
376
``` js
366
- dayjs (' 2019-01-25' ).toISOString (); // '2019-01-25T02:00:00.000Z'
377
+ dayjs (" 2019-01-25" ).toISOString (); // '2019-01-25T02:00:00.000Z'
367
378
```
368
379
369
380
### As Object ` .toObject() `
370
381
371
382
Returns an ` object ` with the date's properties.
372
383
373
384
``` js
374
- dayjs (' 2019-01-25' ).toObject ();
385
+ dayjs (" 2019-01-25" ).toObject ();
375
386
/* { years: 2019,
376
387
months: 0,
377
388
date: 25,
@@ -386,7 +397,7 @@ dayjs('2019-01-25').toObject();
386
397
Returns a ` string ` representation of the date.
387
398
388
399
``` js
389
- dayjs (' 2019-01-25' ).toString (); // 'Fri, 25 Jan 2019 02:00:00 GMT'
400
+ dayjs (" 2019-01-25" ).toString (); // 'Fri, 25 Jan 2019 02:00:00 GMT'
390
401
```
391
402
392
403
## Query
@@ -397,7 +408,7 @@ Returns a `boolean` indicating whether the `Dayjs`'s date is before the other su
397
408
398
409
``` js
399
410
dayjs ().isBefore (dayjs ()); // false
400
- dayjs ().isBefore (dayjs (), ' year' ); // false
411
+ dayjs ().isBefore (dayjs (), " year" ); // false
401
412
```
402
413
403
414
### Is Same ` .isSame(compared: Dayjs, unit?: string) `
@@ -406,7 +417,7 @@ Returns a `boolean` indicating whether the `Dayjs`'s date is the same as the oth
406
417
407
418
``` js
408
419
dayjs ().isSame (dayjs ()); // true
409
- dayjs ().isSame (dayjs (), ' year' ); // true
420
+ dayjs ().isSame (dayjs (), " year" ); // true
410
421
```
411
422
412
423
### Is After ` .isAfter(compared: Dayjs, unit?: string) `
@@ -415,7 +426,7 @@ Returns a `boolean` indicating whether the `Dayjs`'s date is after the other sup
415
426
416
427
``` js
417
428
dayjs ().isAfter (dayjs ()); // false
418
- dayjs ().isAfter (dayjs (), ' year' ); // false
429
+ dayjs ().isAfter (dayjs (), " year" ); // false
419
430
```
420
431
421
432
### Is a Dayjs ` .isDayjs(compared: any) `
@@ -430,7 +441,7 @@ dayjs.isDayjs(new Date()); // false
430
441
The operator ` instanceof ` works equally well:
431
442
432
443
``` js
433
- dayjs () instanceof dayjs // true
444
+ dayjs () instanceof dayjs; // true
434
445
```
435
446
436
447
## Plugin APIs
0 commit comments