time Module

The time module provides APIs for reading the game clock. The game clock is a persisted clock that begins at zero when the server is started for the first time. The game clock is monotonic (always increases - never goes backwards) and is persisted across server runs.

The game clock also provides an in-game calendar based on the game clock. The in-game calendar tracks the time by hour, day, week, month, season, and year. The length of each of these periods is configurable through the client and server configuration files.

The clock provides two types of times, absolute and relative. Absolute times give the number of periods elapsed since the game clock first started. Relative times give the number of periods within a larger period (e.g. month of year). In general, absolute times are monotonic, while relative times will repeat periodically.

It is not possible to set the game clock through a script. The game clock is intended to be monotonic, and allowing a script to modify the time would break this guarantee. In exchange for this limitation, the game clock can be used to accurately and reliably schedule future events (e.g. “replace this sapling with a full-grown tree after one season”).

Note

All numeric time values start at zero (e.g. GetMonthOfYear runs from 0 to 11 if there are twelve months in a year).

Time Functions

GetAbsoluteTime()

Definition

time.GetAbsoluteTime()

Gets the absolute time in the game world, measured in seconds since the game started.

Returns:

Absolute time in seconds.

Return type:

integer

Example

Getting the absolute time using time.GetAbsoluteTime.
local absoluteTime = time.GetAbsoluteTime()

GetYear()

Definition

time.GetYear()

Gets the current year in the game world.

Returns:

Current year.

Return type:

integer

Example

Getting the current year using time.GetYear.
local year = time.GetYear()

GetSeason()

Definition

time.GetSeason()

Gets the current season in the game world.

Returns:

Current season.

Return type:

string

Example

Getting the current season using time.GetSeason.
local season = time.GetSeason()

GetMonth()

Definition

time.GetMonth()

Gets the current month in the game world.

Returns:

Current month.

Return type:

integer

Example

Getting the current month using time.GetMonth.
local month = time.GetMonth()

GetMonthOfYear()

Definition

time.GetMonthOfYear()

Gets the current month of the year in the game world.

Returns:

Current month of the year.

Return type:

integer

Example

Getting the current month of the year using time.GetMonthOfYear.
local monthOfYear = time.GetMonthOfYear()

GetWeekOfMonth()

Definition

time.GetWeekOfMonth()

Gets the current week of the month in the game world.

Returns:

Current week of the month.

Return type:

integer

Example

Getting the current week of the month using time.GetWeekOfMonth.
local weekOfMonth = time.GetWeekOfMonth()

GetDayOfMonth()

Definition

time.GetDayOfMonth()

Gets the current day of the month in the game world.

Returns:

Current day of the month.

Return type:

integer

Example

Getting the current day of the month using time.GetDayOfMonth.
local dayOfMonth = time.GetDayOfMonth()

GetWeek()

Definition

time.GetWeek()

Gets the current week in the game world.

Returns:

Current week.

Return type:

integer

Example

Getting the current week using time.GetWeek.
local week = time.GetWeek()

GetDayOfWeek()

Definition

time.GetDayOfWeek()

Gets the current day of the week in the game world.

Returns:

Current day of the week.

Return type:

integer

Example

Getting the current day of the week using time.GetDayOfWeek.
local dayOfWeek = time.GetDayOfWeek()

GetDay()

Definition

time.GetDay()

Gets the current day in the game world.

Returns:

Current day.

Return type:

integer

Example

Getting the current day using time.GetDay.
local day = time.GetDay()

GetHourOfDay()

Definition

time.GetHourOfDay()

Gets the current hour of the day in the game world.

Returns:

Current hour of the day.

Return type:

integer

Example

Getting the current hour of the day using time.GetHourOfDay.
local hourOfDay = time.GetHourOfDay()

GetSecondOfDay()

Definition

time.GetSecondOfDay()

Gets the current second of the day in the game world.

Returns:

Current second of the day.

Return type:

integer

Example

Getting the current second of the day using time.GetSecondOfDay.
local secondOfDay = time.GetSecondOfDay()