Skip to main content

Date

Table of tokens#

Year, month, and day tokens#
signdesclengthrangeexample
dDay of the month, padded to 2201-3102
DDay of the week, as an abbreviate localized string3Mon-SunMon
jDay of the month, no padding-1-312
SEnglish ordinal suffix for the day of the month, 2 characters. Eg: st, nd, rd or th. Works well with j2st/nd/rd/thth
lDay of the week, as an unabbreviated localized string-Monday-SundayMonday
FMonth as an unabbreviated localized string-January-DecemberJanuary
mMonth, padded to 2201-1201
MMonth as an abbreviated localized string3Jan-DecJan
nMonth, no padding-1-121
YFour-digit year40000-99992006
yTwo-digit year200-9906
UUnix timestamp in seconds10-1611818268
uMillisecond, padded to 33-999
QQuarter11-41
CCentury-0-9921
Hour, minute, second, and offset tokens#
signdesclengthrangeexample
aLowercase morning or afternoon sign2am/pmpm
AUppercase morning or afternoon sign2AM/PMPM
gHour in 12-hour time, no padding-1-123
GHour in 24-hour time, no padding-0-2315
hHour in 12-hour time, padded to 2200-1103
HHour in 24-hour time, padded to 2200-2315
iMinute, padded to 2201-5904
sSecond, padded to 2201-5905
ODifference to Greenwich time (GMT) without colon between hours and minutes--+0700
PDifference to Greenwich time (GMT) with colon between hours and minutes--+07:00
TAbbreviated timezone--MST
Week year, week, and weekday tokens#
signdesclengthrangeexample
WISO8601 week of the year-1-521
NISO8601 day of the week11-71
LWhether it's a leap year10-10
wDay of the week10-61
tTotal days of the month228-3131
zDay of the year-0-3652
Locale-aware formats#
signdesclengthrangeexample
cISO8601 date--2006-01-02T15:04:05-07:00
rRFC2822 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.