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

days(n)shared
Creates a Time object representing a certain amount of days.
Same as nice, but performs formatting.
hours(n)shared
Creates a Time object representing a certain amount of hours.
Initializes a new Time object that represents a time interval.
Creates a Time object representing a certain amount of milliseconds.
Creates a Time object representing a certain amount of minutes.
months(n)shared
Creates a Time object representing a certain amount of months.
Creates a nice string representation of time.
Creates a nice string representation of a point in time relative to now.
now()shared
Returns the current date-time.
Creates a Time object representing a certain amount of seconds.
Formats date-time using a format string.
Returns the following day's date.
weeks(n)shared
Creates a Time object representing a certain amount of weeks.
years(n)shared
Creates a Time object representing a certain amount of years.
Returns the previous day's date.

Methods

Time:days(n)

shared lib/stdlib/sh_time.lua:107

Creates a Time object representing a certain amount of days.

Parameters

  • n Number amount of days

Returns

  • Time

Time:format_nice(suffix, from_now, amt, lang)

shared lib/stdlib/sh_time.lua:241

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 language language to translate to

Returns

  • String phrases

Time:hours(n)

shared lib/stdlib/sh_time.lua:100

Creates a Time object representing a certain amount of hours.

Parameters

  • n Number amount of hours

Returns

  • Time

Time:init(seconds)

shared lib/stdlib/sh_time.lua:68

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

Time:milliseconds(n)

shared lib/stdlib/sh_time.lua:79

Creates a Time object representing a certain amount of milliseconds.

Parameters

  • n Number amount of milliseconds

Returns

  • Time

Time:minutes(n)

shared lib/stdlib/sh_time.lua:93

Creates a Time object representing a certain amount of minutes.

Parameters

  • n Number amount of minutes

Returns

  • Time

Time:months(n)

shared lib/stdlib/sh_time.lua:121

Creates a Time object representing a certain amount of months.

Parameters

  • n Number amount of months

Returns

  • Time

Time:nice(time)

shared lib/stdlib/sh_time.lua:174

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

Time:nice_from_now(time)

shared lib/stdlib/sh_time.lua:212

Creates a nice string representation of a point in time relative to now.

Parameters

  • time Number/Date optional, defaults to current time UNIX 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

Time:now()

shared lib/stdlib/sh_time.lua:285

Returns the current date-time.

Returns

  • DateTime present time

See also

Time:seconds(n)

shared lib/stdlib/sh_time.lua:86

Creates a Time object representing a certain amount of seconds.

Parameters

  • n Number amount of seconds

Returns

  • Time

Time:strftime(fmt, time)

shared lib/stdlib/sh_time.lua:278

Formats 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

See also

Time:tomorrow()

shared lib/stdlib/sh_time.lua:292

Returns the following day's date.

Returns

  • Date tomorrow

See also

  • DateTime#tomorrow

Time:weeks(n)

shared lib/stdlib/sh_time.lua:114

Creates a Time object representing a certain amount of weeks.

Parameters

  • n Number amount of weeks

Returns

  • Time

Time:years(n)

shared lib/stdlib/sh_time.lua:128

Creates a Time object representing a certain amount of years.

Parameters

  • n Number amount of years

Returns

  • Time

Time:yesterday()

shared lib/stdlib/sh_time.lua:299

Returns the previous day's date.

Returns

  • Date yesterday

See also

  • DateTime#yesterday

Defined in