Formatting dates
Information about formatting dates and time (datetime) with the Docly format function.
Docly extends JS to handle dates the same way .NET does (through its docly... functions), as Javascript has a very poor handling of dates.
Important! To set correct language first use the docly.setCulture function. Without it, the invariant culture is used (English names).
To format a date use the docly.format function.
Example:
/* Uses "new Date" which gives "Now" value */
#docly.format(new Date(), "dd. MMM yyyy")#
/* Got a string in a date? */
#docly.format(new Date(mystring), "dd. MM yy")# A single letter on its own is a standard format, not the specifier in the table. docly.format uses .NET formatting: "d" alone gives the short date (e.g. 06/15/2009), and "h" alone throws an error. To get the meaning in the table from one letter, put a % in front: "%d" gives the day of the month, "%h" the hour. Inside a longer pattern ("d. MMM") the letters work as listed.
Format specifier | Description | Examples |
|---|---|---|
"d" | The day of the month, from 1 through 31. | 2009-06-01T13:45:30 -> 1 |
"dd" | The day of the month, from 01 through 31. | 2009-06-01T13:45:30 -> 01 |
"ddd" | The abbreviated name of the day of the week. | 2009-06-15T13:45:30 -> Mon (en-US) |
"dddd" | The full name of the day of the week. | |
"h" | The hour, using a 12-hour clock from 1 to 12. | |
"hh" | The hour, using a 12-hour clock from 01 to 12. | |
"H" | The hour, using a 24-hour clock from 0 to 23. | |
"HH" | The hour, using a 24-hour clock from 00 to 23. | |
"m" | The minute, from 0 through 59. | |
"mm" | The minute, from 00 through 59. | |
"M" | The month, from 1 through 12. | |
"MM" | The month, from 01 through 12. | |
"MMM" | The abbreviated name of the month. | |
"MMMM" | The full name of the month. | |
"s" | The second, from 0 through 59. | |
"ss" | The second, from 00 through 59. | |
"y" | The year, from 0 to 99. | |
"yy" | The year, from 00 to 99. | |
"yyy" | The year, with a minimum of three digits. | |
"yyyy" | The year as a four-digit number. | |
"yyyyy" | The year as a five-digit number. | |
"tt" | The AM/PM designator. | 2009-06-15T13:45:30 -> PM (en-US) |
\ | The escape character. | |
Any other character | The character is copied to the result string unchanged | 2009-06-15T01:45:30 (arr hh:mm t) -> arr 01:45 A |
"fff" | Milliseconds, three digits. | 2009-06-15T13:45:30.617 -> 617 |
"zzz" | Offset from UTC, hours and minutes. | +02:00 |
"%d", "%h", "%M" … | A single specifier on its own (see the warning above). | 2009-06-15 -> 15 for "%d" |
"d" (alone) | Standard format: short date. | 06/15/2009 (invariant culture) |
"D" (alone) | Standard format: long date. | Monday, 15 June 2009 |
"t" / "T" (alone) | Standard format: short / long time. | 13:45 / 13:45:30 |
"g" / "G" (alone) | Standard format: date and short / long time. | |
"o" (alone) | Round-trip ISO 8601 date and time. | 2009-06-15T13:45:30+02:00 |
"s" (alone) | Sortable ISO 8601 date and time. | 2009-06-15T13:45:30 |
"u" (alone) | Universal sortable date and time. | 2009-06-15 13:45:30Z |