DateTime
Converts timestamps to and from structured time. Offers string formatting options for the time.
- namespace DateTime
class Moment[link]
Represents a single instant in time in a given time zone as a structured value.
function at(year, month, day, hour, minute, second, timezone)[link]
Creates a new Moment based on a human-readable timestamp.
Arguments
Name | Type | Optional | Description |
---|---|---|---|
year | integer | The year in 4-digit format |
|
month | integer | A month number (1-12) |
|
day | integer | A day number (1-31) |
|
hour | integer | An hour number in 24-hour format (0-23) |
|
minute | integer | A minute number (0-59) |
|
second | float | A second number. Unlike the previous parameters, this can be a float to represent fractional seconds. (0-59.999...) |
|
timezone | DateTime.TimeZone | Optional | A time zone for this timestamp. Uses local time if not specified. |
Return Value
Type | Description |
---|---|
DateTime.Moment | A new moment instance for the given time. |
function format(template)[link]
Creates a formatted string representing this Moment.
The input string is a template containing directives in the form of a percent sign (%) followed by a single letter.
For example, a string of "%F %j%S, %Y at %g:%i %A" will produce a string like "January 9th, 2009 at 4:28 PM".
The full list of directives is listed in this table:
%y | The year in 2-digit format |
%Y | The year in 4-digit format |
%L | 1 if this is a leap year, 0 otherwise |
%M | The month expressed as a 3-letter abbreviation e.g. Aug |
%F | The month fully written out e.g. August |
%m | The month as a 2-digit number with leading 0 for single-digit months |
%n | The month as an integer with no leading 0's |
%t | The number of days in the month |
%d | The day as a 2-digit number |
%j | The day as an integer with no leading 0's |
%S | The ordinal suffix of the day. e.g. "nd" if it's the 22nd of the month |
%z | The current day number as a number of days from the beginning of the year. e.g. January 1st is 0 and December 31st is 364 in non-leap years. |
%D | The day of the week as a 3-letter abbreviation e.g. Thu |
%N | The day of the week fully spelled out e.g. Wednesday |
%a | "am" or "pm" |
%A | "AM" or "PM" |
%g | The current hour in 12-hour format |
%G | The current hour in 24-hour format |
%h | The current hour in 12-hour format as a 2-digit number with leading 0's if necessary |
%H | The current hour in 24-hour format as a 2-digit number with leading 0's if necessary |
%i | The current minute as a 2-digit number |
%s | The current seconds as a 2-digit number |
%v | The current number of milliseconds as a 3-digit number |
%u | The current number of microseconds as a 6-digit number. This is redundant with millis. |
%U | The current unix timestamp. |
Arguments
Name | Type | Description |
---|---|---|
template | string | A template string containing directives |
function fromTimestamp(timestamp, timezone)[link]
Creates a new Moment instance based on the given timestamp and timezone.
Arguments
Name | Type | Optional | Description |
---|---|---|---|
timestamp | float | The unix timestamp of this moment |
|
timezone | DateTime.TimeZone | Optional | The timezone of the moment. Uses local time if not specified. |
Return Value
Type | Description |
---|---|
DateTime.Moment | A new Moment instance for the given time. |
function getFormattedOffset()[link]
Returns the UTC offset as a standardized readable string in the format of UTC+HH:MM or UTC-HH:MM.
Return Value
Type | Description |
---|---|
string | The formatted UTC offset. |
function getUtcOffsetSeconds()[link]
Gets the number of seconds from the same time in UTC.
Return Value
Type | Description |
---|---|
integer | Number of seconds from UTC for the Moment's time zone at the given time. Note on sign: Adding this value to UTC will give you this Moment's time. Subtracting this value from the Moment's time will give you UTC time. |
function isDstOccuring()[link]
Checks if Daylight Savings Time is curring in the given moment.
Return Value
Type | Description |
---|---|
boolean | True if DST is happening. |
function now(timezone)[link]
Creates a new Moment that represents the current time.
Arguments
Name | Type | Optional | Description |
---|---|---|---|
timezone | DateTime.TimeZone | Optional | Time zone of the moment. Uses local time if not specified. |
Return Value
Type | Description |
---|---|
DateTime.Moment | A new moment instance for the current time. |