DateTime

Constructors

NameDescription
now()Returns a DateTime representing the current moment in time.
fromUnixTimestamp(unixTimestamp: number)Returns a DateTime representing the given Unix timestamp, in seconds since the Unix epoch (January 1st, 1970, 00:00 UTC).
fromUnixTimestampMillis(unixTimestampMillis: number)Returns a DateTime representing the given Unix timestamp, in milliseconds since the Unix epoch.
fromUniversalTime(year: number,month: number,day: number,hour: number,minute: number,second: number,millisecond: number)Returns a new DateTime from the given UTC time units. All parameters are optional (year defaults to 1970, month and day default to 1, the rest default to 0).
fromLocalTime(year: number,month: number,day: number,hour: number,minute: number,second: number,millisecond: number)Returns a new DateTime from the given local time units, using the same optional parameters and defaults as fromUniversalTime.
fromIsoDate(isoDate: string)Returns a DateTime parsed from the given ISO 8601 date-time string, interpreted as UTC.

Code Snippet

local now = DateTime.now()
print(now.UnixTimestamp)

local event = DateTime.fromUniversalTime(2026, 1, 1, 12, 0, 0)
print(event:ToIsoDate())
print(event:FormatUniversalTime("LLL", "en-us"))

Properties

NameTypeDescription
UnixTimestampnumberThe number of seconds between January 1st, 1970 at 00:00 UTC (the Unix epoch) and this DateTime.
UnixTimestampMillisnumberThe number of milliseconds between January 1st, 1970 at 00:00 UTC (the Unix epoch) and this DateTime.

Methods

NameParametersReturnsDescription
ToUniversalTime():DictionaryVoidDictionaryConverts the DateTime to a table of UTC time components: Year, Month, Day, Hour, Minute, Second, Millisecond.
ToLocalTime():DictionaryVoidDictionaryConverts the DateTime to a table of local time components, with the same keys as ToUniversalTime().
ToIsoDate():stringVoidstringReturns the DateTime as an ISO 8601 date-time string, for example "2020-01-02T10:30:45Z".
FormatUniversalTime(format: string,locale: string):stringformat: string, locale: stringstringFormats the DateTime's UTC value into a string using the given format tokens and locale.
FormatLocalTime(format: string,locale: string):stringformat: string, locale: stringstringFormats the DateTime's local time value into a string using the given format tokens and locale.