The DateTime class represents a point in time, not a time interval. For time intervals, please use Time.

See also

Summary

Methods

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

DateTime:at(seconds, timezone)

shared lib/stdlib/sh_datetime.lua:66

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

Initializes 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'

DateTime:iso(time)

shared lib/stdlib/sh_datetime.lua:105

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.time UNIX time

Returns

  • String ISO date format

DateTime:now()

shared lib/stdlib/sh_datetime.lua:73

Returns the current date-time.

Returns

  • DateTime present time

DateTime:to_date()

shared lib/stdlib/sh_datetime.lua:87

Converts the DateTime object to Date.

Returns

  • Date this DateTime as Date

DateTime:to_time()

shared lib/stdlib/sh_datetime.lua:93

Converts the DateTime object to Time.

Returns

  • Time this DateTime as Time

DateTime:utc(time)

shared lib/stdlib/sh_datetime.lua:80

Get the UTC time, or alternatively a UTC time at a specified UNIX timestamp.

Parameters

  • time Number optional, defaults to self.time UNIX time

Returns

  • DateTime

DateTime:zone()

shared lib/stdlib/sh_datetime.lua:58

Gets the timezone abbreviation / information string.

Returns

  • String time zone

Defined in