Date class
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(right)shared
Add the specified amount of Time to the Date.
__concat(right)shared
Add the specified amount of Time to the Date.
__sub(right)shared
Subtracts the specified amount of Time from the Date.
__tostring()shared
Converts this Date object to an ISO-8601 string.
at(seconds)shared
Returns the date at a specified point in time.
init(year, month, day)shared
Initializes a new Date object.
iso(time)shared
Converts the Date object into an ISO string.
strftime(fmt, time)shared
Formats the date-time using a format string.
to_datetime()shared
Converts the Date object to DateTime.
to_time()shared
Converts the Date object to Time.
today()shared
Returns the current date.
tomorrow()shared
Returns the following day's date.
yesterday()shared
Returns the previous day's date.
Methods
Add the specified amount of Time to the Date.
Parameters
- right Time
Returns
- Date or DateTime
Add the specified amount of Time to the Date.
Parameters
- right Time
Returns
- Date or DateTime
See also
Subtracts the specified amount of Time from the Date.
Parameters
- right Time
Returns
- Date or DateTime
Converts this Date object to an ISO-8601 string.
Returns
- String ISO representation of the Date
Returns the date at a specified point in time.
Parameters
- seconds Number UNIX timestamp
Returns
- Date
Initializes a new Date object.
local my_birthday = Date.new(1999, 12, 4) -- December 4, 1999
Parameters
- year Number
- month Number
- day Number
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.timeUNIX time
Returns
- String ISO date format
Formats the date-time using a format string.
Parameters
- fmt String os.date format
- time Number optional, defaults to
self.timeUNIX time
Returns
- String formatted string
Converts the Date object to DateTime.
Returns
- DateTime this Date as DateTime
Converts the Date object to Time.
Returns
- Time this Date as Time
Returns the current date.
Returns
- Date today
Returns the following day's date.
Returns
- Date tomorrow
Returns the previous day's date.
Returns
- Date yesterday