Time class
The Time class represents a time interval, not a point in time. For points in time, please use Date or DateTime.
See also
Summary
Methods
Methods
Creates a Time object representing a certain amount of days.
Parameters
- n Number amount of days
Returns
- Time
Same as nice, but performs formatting. Takes the three values that nice returns and translates them into readable text. The amount is rounded down, with 'about' or 'over' in front of it if anything was cut off, and is never shown as less than 1. The unit is translated in the plural form that fits the rounded amount, for languages whose time phrases have plural forms.
The 'time.from_now' and 'time.ago' phrases are templates with a {time} placeholder for
the amount and unit, so that every language puts them where its grammar needs them
('{time} ago', 'hace {time}', '{time} назад'). A phrase without the placeholder is
appended after the amount and unit.
local text = Time:format_nice(Time:minutes(5):nice()) -- e.g. '5 minutes from now'
Parameters
- suffix String time phrase, as returned by nice
- from_now String 'time.from_now' or 'time.ago' phrase or an empty string, as returned by nice
- amt Number amount of time, as returned by nice
- lang String optional, defaults to
current languagelanguage to translate to
Returns
- String phrases
Creates a Time object representing a certain amount of hours.
Parameters
- n Number amount of hours
Returns
- Time
Initializes a new Time object that represents a time interval.
local two_days = Time:days(2)
local a_day_after_tomorrow = Date:today() + two_days
Parameters
- seconds Number optional, defaults to
os.time()length of the interval in seconds
Creates a Time object representing a certain amount of milliseconds.
Parameters
- n Number amount of milliseconds
Returns
- Time
Creates a Time object representing a certain amount of minutes.
Parameters
- n Number amount of minutes
Returns
- Time
Creates a Time object representing a certain amount of months.
Parameters
- n Number amount of months
Returns
- Time
Creates a nice string representation of time. The unit is singular ('time.hour') while the amount is below 2 and plural ('time.hours') from 2 on, so that the amount, which format_nice rounds down, always agrees with the unit.
Parameters
- time Number optional, defaults to
self.time
Returns
- String time phrase
- String 'time.from_now' or 'time.ago' phrase (empty for 'time.just_now')
- Number amount of time in the unit of the phrase
See also
Creates a nice string representation of a point in time relative to now.
Parameters
- time Number/Date optional, defaults to
current timeUNIX time, or a Date or DateTime object
Returns
- String time phrase
- String 'time.from_now' for a time in the future or 'time.ago' for one in the past (empty for 'time.just_now')
- Number amount of time in the unit of the phrase
See also
Returns the current date-time.
Returns
- DateTime present time
See also
Creates a Time object representing a certain amount of seconds.
Parameters
- n Number amount of seconds
Returns
- Time
Formats date-time using a format string.
Parameters
- fmt String os.date format
- time Number optional, defaults to
self.timeUNIX time
Returns
- String formatted string
See also
Returns the following day's date.
Returns
- Date tomorrow
See also
DateTime#tomorrow
Creates a Time object representing a certain amount of weeks.
Parameters
- n Number amount of weeks
Returns
- Time
Creates a Time object representing a certain amount of years.
Parameters
- n Number amount of years
Returns
- Time
Returns the previous day's date.
Returns
- Date yesterday
See also
DateTime#yesterday