os
A reduced operating system library. Only time and clock functions remain: clock, date, difftime and time.
Removed functions
os.execute, os.exit, os.getenv, os.remove, os.rename, os.tmpname and os.setlocale are removed and are nil in this VM. File access goes through the client file API.
Functions
os.clock(): number
os.clock(): number
- Returns the CPU time used by the process, in seconds. Useful to measure elapsed work, not wall-clock time.
local t0 = os.clock()
local dt = os.clock() - t0
os.date(format?: string = "%c", time?: number = os.time()): string | table
os.date(format?: string = "%c", time?: number = os.time()): string | table
- Formats
time(seconds since 1970-01-01 UTC) according toformat. - A leading
!formats in UTC; otherwise local time is used. "*t"(or"!*t") returns a table with the fieldsyear,month,day,hour,min,sec,wday(1 is Sunday),yday(1 to 366) andisdst(boolean).- Otherwise the format is a C
strftimestring; directives below are supported. An invalid directive raises an error.
print(os.date("%Y-%m-%d %H:%M:%S"))
local t = os.date("*t")
print(t.year, t.month, t.day)
os.difftime(t2: number, t1: number): number
os.difftime(t2: number, t1: number): number
- Returns the number of seconds from time
t1to timet2.
os.time(t?: table): number
os.time(t?: table): number
- With no argument, returns the current time in seconds since 1970-01-01 UTC.
- With a table, reads the fields
year,month,day,hour(default 12),min(default 0),sec(default 0) andisdst(optional boolean) as local time and returns the corresponding timestamp. year,monthanddayare required. Out-of-range fields are normalized (month 13 is January of the next year).- Returns
nilif the time cannot be represented.
print(os.time({ year = 2026, month = 1, day = 1, hour = 0 }))