source: trip-planner-front/node_modules/date-format/README.md@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[6a3a178]1date-format
2===========
3
4node.js formatting of Date objects as strings. Probably exactly the same as some other library out there.
5
6```sh
7npm install date-format
8```
9
10usage
11=====
12
13Formatting dates as strings
14----
15
16```javascript
17var format = require('date-format');
18format.asString(); //defaults to ISO8601 format and current date.
19format.asString(new Date()); //defaults to ISO8601 format
20format.asString('hh:mm:ss.SSS', new Date()); //just the time
21```
22
23or
24
25```javascript
26var format = require('date-format');
27format(); //defaults to ISO8601 format and current date.
28format(new Date());
29format('hh:mm:ss.SSS', new Date());
30```
31
32Format string can be anything, but the following letters will be replaced (and leading zeroes added if necessary):
33* dd - `date.getDate()`
34* MM - `date.getMonth() + 1`
35* yy - `date.getFullYear().toString().substring(2, 4)`
36* yyyy - `date.getFullYear()`
37* hh - `date.getHours()`
38* mm - `date.getMinutes()`
39* ss - `date.getSeconds()`
40* SSS - `date.getMilliseconds()`
41* O - timezone offset in +hm format (note that time will be in UTC if displaying offset)
42
43Built-in formats:
44* `format.ISO8601_FORMAT` - `2017-03-14T14:10:20.391` (local time used)
45* `format.ISO8601_WITH_TZ_OFFSET_FORMAT` - `2017-03-14T03:10:20.391+1100` (UTC + TZ used)
46* `format.DATETIME_FORMAT` - `14 03 2017 14:10:20.391` (local time used)
47* `format.ABSOLUTETIME_FORMAT` - `14:10:20.391` (local time used)
48
49Parsing strings as dates
50----
51The date format library has limited ability to parse strings into dates. It can convert strings created using date format patterns (as above), but if you're looking for anything more sophisticated than that you should probably look for a better library ([momentjs](https://momentjs.com) does pretty much everything).
52
53```javascript
54var format = require('date-format');
55// pass in the format of the string as first argument
56format.parse(format.ISO8601_FORMAT, '2017-03-14T14:10:20.391');
57// returns Date
58```
Note: See TracBrowser for help on using the repository browser.