The Date class is the base class of DateTime. The Date class represents a point in time, not a time interval. For time intervals, please use Time.

See also

Summary

Methods

Add the specified amount of Time to the Date.
Add the specified amount of Time to the Date.
Subtracts the specified amount of Time from the Date.
Converts this Date object to an ISO-8601 string.
Returns the date at a specified point in time.
Initializes a new Date object.
iso(time)shared
Converts the Date object into an ISO string.
Formats the date-time using a format string.
Converts the Date object to DateTime.
to_time()shared
Converts the Date object to Time.
today()shared
Returns the current date.
Returns the following day's date.
Returns the previous day's date.

Methods

Date:__add(right)

shared lib/stdlib/sh_date.lua:118

Add the specified amount of Time to the Date.

Parameters

  • right Time

Returns

  • Date or DateTime

Date:__concat(right)

shared lib/stdlib/sh_date.lua:137

Add the specified amount of Time to the Date.

Parameters

  • right Time

Returns

  • Date or DateTime

See also

Date:__sub(right)

shared lib/stdlib/sh_date.lua:127

Subtracts the specified amount of Time from the Date.

Parameters

  • right Time

Returns

  • Date or DateTime

Date:__tostring()

shared lib/stdlib/sh_date.lua:145

Converts this Date object to an ISO-8601 string.

Returns

  • String ISO representation of the Date

Date:at(seconds)

shared lib/stdlib/sh_date.lua:71

Returns the date at a specified point in time.

Parameters

  • seconds Number UNIX timestamp

Returns

  • Date

Date:init(year, month, day)

shared lib/stdlib/sh_date.lua:24

Initializes a new Date object.

local my_birthday = Date.new(1999, 12, 4) -- December 4, 1999

Parameters

  • year Number
  • month Number
  • day Number

Date:iso(time)

shared lib/stdlib/sh_date.lua:96

Converts the Date object into an ISO string. If the first argument is given, converts the given UNIX time into the ISO date.

print(date_obj:iso()) -- current date, such as "2019-09-24"
print(Date:iso(1569283200)) -- 2019-09-24

Parameters

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

Returns

  • String ISO date format

Date:strftime(fmt, time)

shared lib/stdlib/sh_date.lua:104

Formats the date-time using a format string.

Parameters

  • fmt String os.date format
  • time Number optional, defaults to self.time UNIX time

Returns

  • String formatted string

Date:to_datetime()

shared lib/stdlib/sh_date.lua:78

Converts the Date object to DateTime.

Returns

  • DateTime this Date as DateTime

Date:to_time()

shared lib/stdlib/sh_date.lua:84

Converts the Date object to Time.

Returns

  • Time this Date as Time

Date:today()

shared lib/stdlib/sh_date.lua:49

Returns the current date.

Returns

  • Date today

Date:tomorrow()

shared lib/stdlib/sh_date.lua:56

Returns the following day's date.

Returns

  • Date tomorrow

Date:yesterday()

shared lib/stdlib/sh_date.lua:63

Returns the previous day's date.

Returns

  • Date yesterday

Defined in