Open Source Cross-Platform Game Programming

DateTime

Converts timestamps to and from structured time. Offers string formatting options for the time.

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

NameTypeOptionalDescription
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

TypeDescription
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:

%yThe year in 2-digit format
%YThe year in 4-digit format
%L1 if this is a leap year, 0 otherwise
%MThe month expressed as a 3-letter abbreviation e.g. Aug
%FThe month fully written out e.g. August
%mThe month as a 2-digit number with leading 0 for single-digit months
%nThe month as an integer with no leading 0's
%tThe number of days in the month
%dThe day as a 2-digit number
%jThe day as an integer with no leading 0's
%SThe ordinal suffix of the day. e.g. "nd" if it's the 22nd of the month
%zThe 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.
%DThe day of the week as a 3-letter abbreviation e.g. Thu
%NThe day of the week fully spelled out e.g. Wednesday
%a"am" or "pm"
%A"AM" or "PM"
%gThe current hour in 12-hour format
%GThe current hour in 24-hour format
%hThe current hour in 12-hour format as a 2-digit number with leading 0's if necessary
%HThe current hour in 24-hour format as a 2-digit number with leading 0's if necessary
%iThe current minute as a 2-digit number
%sThe current seconds as a 2-digit number
%vThe current number of milliseconds as a 3-digit number
%uThe current number of microseconds as a 6-digit number. This is redundant with millis.
%UThe current unix timestamp.

Arguments

NameTypeDescription
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

NameTypeOptionalDescription
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

TypeDescription
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

TypeDescription
string

The formatted UTC offset.

function getUtcOffsetSeconds()[link]

Gets the number of seconds from the same time in UTC.

Return Value

TypeDescription
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

TypeDescription
boolean

True if DST is happening.

function now(timezone)[link]

Creates a new Moment that represents the current time.

Arguments

NameTypeOptionalDescription
timezone DateTime.TimeZone Optional

Time zone of the moment. Uses local time if not specified.

Return Value

TypeDescription
DateTime.Moment

A new moment instance for the current time.