Initial commit
[yaffs-website] / node_modules / dateformat / Readme.md
1 # dateformat
2
3 A node.js package for Steven Levithan's excellent [dateFormat()][dateformat] function.
4
5 [![Build Status](https://travis-ci.org/felixge/node-dateformat.svg)](https://travis-ci.org/felixge/node-dateformat)
6
7 ## Modifications
8
9 * Removed the `Date.prototype.format` method. Sorry folks, but extending native prototypes is for suckers.
10 * Added a `module.exports = dateFormat;` statement at the bottom
11 * Added the placeholder `N` to get the ISO 8601 numeric representation of the day of the week
12
13 ## Installation
14
15 ```bash
16 $ npm install dateformat
17 $ dateformat --help
18 ```
19
20 ## Usage
21
22 As taken from Steven's post, modified to match the Modifications listed above:
23 ```js
24 var dateFormat = require('dateformat');
25 var now = new Date();
26
27 // Basic usage
28 dateFormat(now, "dddd, mmmm dS, yyyy, h:MM:ss TT");
29 // Saturday, June 9th, 2007, 5:46:21 PM
30
31 // You can use one of several named masks
32 dateFormat(now, "isoDateTime");
33 // 2007-06-09T17:46:21
34
35 // ...Or add your own
36 dateFormat.masks.hammerTime = 'HH:MM! "Can\'t touch this!"';
37 dateFormat(now, "hammerTime");
38 // 17:46! Can't touch this!
39
40 // When using the standalone dateFormat function,
41 // you can also provide the date as a string
42 dateFormat("Jun 9 2007", "fullDate");
43 // Saturday, June 9, 2007
44
45 // Note that if you don't include the mask argument,
46 // dateFormat.masks.default is used
47 dateFormat(now);
48 // Sat Jun 09 2007 17:46:21
49
50 // And if you don't include the date argument,
51 // the current date and time is used
52 dateFormat();
53 // Sat Jun 09 2007 17:46:22
54
55 // You can also skip the date argument (as long as your mask doesn't
56 // contain any numbers), in which case the current date/time is used
57 dateFormat("longTime");
58 // 5:46:22 PM EST
59
60 // And finally, you can convert local time to UTC time. Simply pass in
61 // true as an additional argument (no argument skipping allowed in this case):
62 dateFormat(now, "longTime", true);
63 // 10:46:21 PM UTC
64
65 // ...Or add the prefix "UTC:" or "GMT:" to your mask.
66 dateFormat(now, "UTC:h:MM:ss TT Z");
67 // 10:46:21 PM UTC
68
69 // You can also get the ISO 8601 week of the year:
70 dateFormat(now, "W");
71 // 42
72
73 // and also get the ISO 8601 numeric representation of the day of the week:
74 dateFormat(now,"N");
75 // 6
76 ```
77
78 ### Mask options
79
80 Mask | Description
81 ---- | -----------
82 `d` | Day of the month as digits; no leading zero for single-digit days.
83 `dd` | Day of the month as digits; leading zero for single-digit days.
84 `ddd` | Day of the week as a three-letter abbreviation.
85 `dddd` | Day of the week as its full name.
86 `m` | Month as digits; no leading zero for single-digit months.
87 `mm` | Month as digits; leading zero for single-digit months.
88 `mmm` | Month as a three-letter abbreviation.
89 `mmmm` | Month as its full name.
90 `yy` | Year as last two digits; leading zero for years less than 10.
91 `yyyy` | Year represented by four digits.
92 `h` | Hours; no leading zero for single-digit hours (12-hour clock).
93 `hh` | Hours; leading zero for single-digit hours (12-hour clock).
94 `H` | Hours; no leading zero for single-digit hours (24-hour clock).
95 `HH` | Hours; leading zero for single-digit hours (24-hour clock).
96 `M` | Minutes; no leading zero for single-digit minutes.
97 `MM` | Minutes; leading zero for single-digit minutes.
98 `N` | ISO 8601 numeric representation of the day of the week.
99 `o` | GMT/UTC timezone offset, e.g. -0500 or +0230.
100 `s` | Seconds; no leading zero for single-digit seconds.
101 `ss` | Seconds; leading zero for single-digit seconds.
102 `S` | The date's ordinal suffix (st, nd, rd, or th). Works well with `d`.
103 `l` |  Milliseconds; gives 3 digits.
104 `L` | Milliseconds; gives 2 digits.
105 `t`     | Lowercase, single-character time marker string: a or p.
106 `tt` | Lowercase, two-character time marker string: am or pm.
107 `T` | Uppercase, single-character time marker string: A or P.
108 `TT` | Uppercase, two-character time marker string: AM or PM.
109 `W` | ISO 8601 week number of the year, e.g. 42
110 `Z` | US timezone abbreviation, e.g. EST or MDT. With non-US timezones or in the
111 `'...'`, `"..."` | Literal character sequence. Surrounding quotes are removed.
112 `UTC:` |        Must be the first four characters of the mask. Converts the date from local time to UTC/GMT/Zulu time before applying the mask. The "UTC:" prefix is removed.
113
114 ### Named Formats
115
116 Name | Mask | Example
117 ---- | ---- | -------
118 `default` | `ddd mmm dd yyyy HH:MM:ss` | Sat Jun 09 2007 17:46:21
119 `shortDate` | `m/d/yy` | 6/9/07
120 `mediumDate` | `mmm d, yyyy` | Jun 9, 2007
121 `longDate` | `mmmm d, yyyy` | June 9, 2007
122 `fullDate` | `dddd, mmmm d, yyyy` | Saturday, June 9, 2007
123 `shortTime` | `h:MM TT` | 5:46 PM
124 `mediumTime` | `h:MM:ss TT` | 5:46:21 PM
125 `longTime` | `h:MM:ss TT Z` | 5:46:21 PM EST
126 `isoDate` | `yyyy-mm-dd` | 2007-06-09
127 `isoTime` | `HH:MM:ss` | 17:46:21
128 `isoDateTime` | `yyyy-mm-dd'T'HH:MM:ss` | 2007-06-09T17:46:21
129 `isoUtcDateTime` | `UTC:yyyy-mm-dd'T'HH:MM:ss'Z'` | 2007-06-09T22:46:21Z
130 ## License
131
132 (c) 2007-2009 Steven Levithan [stevenlevithan.com][stevenlevithan], MIT license.
133
134 [dateformat]: http://blog.stevenlevithan.com/archives/date-time-format
135 [stevenlevithan]: http://stevenlevithan.com/