DateTime class
Extends Date
The DateTime class represents a point in time, not a time interval. For time intervals, please use Time.
See also
Summary
Methods
at(seconds, timezone)shared
Returns the date-time at a specified point in time.
Initializes a new DateTime object.
iso(time)shared
Converts the DateTime object into an ISO-8601 string.
now()shared
Returns the current date-time.
to_date()shared
Converts the DateTime object to Date.
to_time()shared
Converts the DateTime object to Time.
utc(time)shared
Get the UTC time, or alternatively a UTC time at a specified UNIX timestamp.
zone()shared
Gets the timezone abbreviation / information string.
Methods
Returns the date-time at a specified point in time.
Parameters
- seconds Number UNIX timestamp
- timezone String time zone
Returns
- DateTime
DateTime:init(year, month, day, hour, minute, second, timezone)
shared lib/stdlib/sh_datetime.lua:22Initializes a new DateTime object.
local my_birthday = DateTime.new(1999, 12, 4, 15, 30, 0) -- 3:30 PM, December 4, 1999
Parameters
- year Number
- month Number
- day Number
- hour Number
- minute Number
- second Number
- timezone String optional, defaults to
'utc'
Converts the DateTime object into an ISO-8601 string. If the first argument is given, converts the given UNIX time into the ISO date.
print(date_time_obj:iso()) -- current date and time in UTC, such as "2019-09-24T18:09:00Z"
print(DateTime:iso(1569283200)) -- 2019-09-24T00:00:00Z
Parameters
- time Number optional, defaults to
self.timeUNIX time
Returns
- String ISO date format
Returns the current date-time.
Returns
- DateTime present time
Converts the DateTime object to Date.
Returns
- Date this DateTime as Date
Converts the DateTime object to Time.
Returns
- Time this DateTime as Time
Get the UTC time, or alternatively a UTC time at a specified UNIX timestamp.
Parameters
- time Number optional, defaults to
self.timeUNIX time
Returns
- DateTime
Gets the timezone abbreviation / information string.
Returns
- String time zone