Date
Table of tokens#
Year, month, and day tokens#
| sign | desc | length | range | example |
|---|---|---|---|---|
| d | Day of the month, padded to 2 | 2 | 01-31 | 02 |
| D | Day of the week, as an abbreviate localized string | 3 | Mon-Sun | Mon |
| j | Day of the month, no padding | - | 1-31 | 2 |
| S | English ordinal suffix for the day of the month, 2 characters. Eg: st, nd, rd or th. Works well with j | 2 | st/nd/rd/th | th |
| l | Day of the week, as an unabbreviated localized string | - | Monday-Sunday | Monday |
| F | Month as an unabbreviated localized string | - | January-December | January |
| m | Month, padded to 2 | 2 | 01-12 | 01 |
| M | Month as an abbreviated localized string | 3 | Jan-Dec | Jan |
| n | Month, no padding | - | 1-12 | 1 |
| Y | Four-digit year | 4 | 0000-9999 | 2006 |
| y | Two-digit year | 2 | 00-99 | 06 |
| U | Unix timestamp in seconds | 10 | - | 1611818268 |
| u | Millisecond, padded to 3 | 3 | - | 999 |
| Q | Quarter | 1 | 1-4 | 1 |
| C | Century | - | 0-99 | 21 |
Hour, minute, second, and offset tokens#
| sign | desc | length | range | example |
|---|---|---|---|---|
| a | Lowercase morning or afternoon sign | 2 | am/pm | pm |
| A | Uppercase morning or afternoon sign | 2 | AM/PM | PM |
| g | Hour in 12-hour time, no padding | - | 1-12 | 3 |
| G | Hour in 24-hour time, no padding | - | 0-23 | 15 |
| h | Hour in 12-hour time, padded to 2 | 2 | 00-11 | 03 |
| H | Hour in 24-hour time, padded to 2 | 2 | 00-23 | 15 |
| i | Minute, padded to 2 | 2 | 01-59 | 04 |
| s | Second, padded to 2 | 2 | 01-59 | 05 |
| O | Difference to Greenwich time (GMT) without colon between hours and minutes | - | - | +0700 |
| P | Difference to Greenwich time (GMT) with colon between hours and minutes | - | - | +07:00 |
| T | Abbreviated timezone | - | - | MST |
Week year, week, and weekday tokens#
| sign | desc | length | range | example |
|---|---|---|---|---|
| W | ISO8601 week of the year | - | 1-52 | 1 |
| N | ISO8601 day of the week | 1 | 1-7 | 1 |
| L | Whether it's a leap year | 1 | 0-1 | 0 |
| w | Day of the week | 1 | 0-6 | 1 |
| t | Total days of the month | 2 | 28-31 | 31 |
| z | Day of the year | - | 0-365 | 2 |
Locale-aware formats#
| sign | desc | length | range | example |
|---|---|---|---|---|
| c | ISO8601 date | - | - | 2006-01-02T15:04:05-07:00 |
| r | RFC2822 date | - | - | Mon, 02 Jan 2006 15:04:05 -0700 |
Supported units#
- Y, year, years
- M, month, months
- D, day, days
- h, hour, hours
- m, minute, minutes
- s, second, seconds
now(format)#
Gets the current UTC date time formatted with the string supplied in the parameters.
Arguments
format (string): The parsing tokens.
Returns
(string): Returns the formatted time.
format(time, format)#
Formats the date time with the format supplied in the parameters.
Arguments
time (string): The ISO date time to format.
format (string): The parsing tokens.
Returns
(string): Returns the formatted time.
parse(time, format)#
Parses the formatted date time to an ISO date time.
Arguments
time (string): The date time to parse.
format (string): The parsing tokens.
Returns
(string): Returns the ISO date time.
add(time, amount, unit)#
Adds time to the ISO given date time.
Arguments
time (string): The ISO date time.
amount (string): The amount of unit to add.
unit (string): The unit.
Returns
(string): Returns the ISO date time.
substract(time, amount, unit)#
Substracts time to the ISO given date time.
Arguments
time (string): The ISO date time.
amount (string): The amount of unit to substract.
unit (string): The unit.
Returns
(string): Returns the ISO date time.
If you get stuck at a point above, please reach out to support@butternut.tech or via this form.
We're here to support you, and together we can build great things.