Table of Contents
kmj-datetime
The kmj-datetime package provides additional date/time handling functions to account for shortcomings with the date/time functions that are a part of the Lua io
package.
The runtime provides this library through the luaL_newlib auxiliary library function, so all fields can be assumed to be functions.
now
The now field contains a function that returns the current time represented as a number with the milliseconds since January 1st, 1970 at 12:00 AM UTC.
Syntax
now(): (timestamp: number)
Arguments
This function takes no arguments.
Returns
- The first return value contains the current time in milliseconds since January 1st, 1970 at 12:00 AM UTC.
fromISO8601
This field contains a function that takes an ISO8601 formatted date/time string and converts it to milliseconds since January 1st, 1970 at 12:00 AM UTC.
Syntax
fromISO8601(iso8601str: string): (timestamp: number|nil)
Arguments
- The first argument should contain the ISO8601 string representation of the timestamp.
Returns
- The first return value will contain the amount of milliseconds since January 1st, 1970 at 12:00 AM UTC that the timestamp represents, or
nil
if the string could not be understood.
toISO8601
Converts a number containing milliseconds since January 1st, 1970 at 12:00 AM UTC to a ISO8601 Zulu string representation.
Syntax
toISO8601(timestamp: number): (iso8601str: string)
Arguments
- The first argument should contain the amount of milliseconds since January 1st, 1970 at 12:00 AM UTC that must be converted to a ISO8601 string.
Returns
- The first return value will be an ISO8601 Zulu string representing the given numeric timestamp.