Skip to main content

Time

Objects of type Timeval represent absolute time points. The time points are internally represented using Coordinated Universal Time(UTC) making them location independent. The time points are internally represented as number of microseconds since January 1st, 1970, which is called the epoch.

Get current time according to UTC by calling:

utc_time()
Not connected

To run this code block you must be logged in and your studio instance must be started.

The time format is year-month-dateThour:minute:second:millisecondZ. The ending Z indicates UTC time, also called Greenwich Mean Time (GMT).

Get the local time by calling:

local_time()
Not connected

To run this code block you must be logged in and your studio instance must be started.

Notice that the local time string depends on where your sa.engine server is located. As an alternative you can get a location independent local time string by calling:

local_utc_time()
Not connected

To run this code block you must be logged in and your studio instance must be started.

The ending hh:ss indicates the time shift in hours and minutes needed to get UTC time.

Get the current time point by calling:

now()
Not connected

To run this code block you must be logged in and your studio instance must be started.

Constants of type Timeval are written as |UTC-time|.

You can create new time points by adding or subtracting seconds from time points using + or -, respectively:

set :t1=now();
:t1 + 1;
:t1 - 1
Not connected

To run this code block you must be logged in and your studio instance must be started.

You can get the time in seconds between two time points by using -, e.g.:

set :t1 = now();
set :t2 = :t1 + 2;
:t2 - :t1
Not connected

To run this code block you must be logged in and your studio instance must be started.

The function call sleep(x) makes the system sleep for x seconds. Try:

set :t1 = now();
sleep(0.2);
now() - :t1
Not connected

To run this code block you must be logged in and your studio instance must be started.

Functions

clock()->Number

The number of seconds since the system was started


local_time(Timeval tv)->Charstring

Convert time point tv into local ISO time string


local_time()->Charstring

The current time as local ISO time string


local_utc_time(Timeval tv)->Charstring

Convert time point tv into local UTC time string


local_utc_time()->Charstring

The current local time as ISO UTC time string


minus(Timeval tv,Number sec)->Timeval

tv - sec


minus(Timeval tv1,Timeval tv2)->Real

tv2 - tv1


now()->Timeval

Current time point


parse_iso_timestamp(Charstring ts)->Timeval

Convert ISO time string ts into time point


plus(Number sec,Timeval tv)->Timeval

sec + tv


plus(Timeval tv,Number sec)->Timeval

tv + sec


real(Timeval tv)->Real r

Convert time point tv into number of seconds since epoch


rnow()->Real

The current time as number of seconds since epoch


sec(Timeval tv)->Integer

Second in time point tv


shift(Timeval tv,Number sec)->Timeval

Shift sec seconds from time point tv. Same as tv+sec


sleep(Number sec)->Number

Sleep for sec seconds


span(Timeval tv1,Timeval tv2)->Real

The difference in seconds between time points tv2 and tv1. Same as tv2-tv1


timestamp(Timeval o)->Timeval

Get the timestamp of timestamped object o


timeval(Number r)->Timeval t

Convert number of seconds since epoch r into time point


timeval(Vector tv)->Timeval

The time point of a UTC time vector [year, month, day, hour, minute, microsecond]


time_vector(Timeval tv)->Vector of Number

The components of time point tv as a UTC time vector [year, month, day, hour, minute, microsecond]


time_zone()->Number

Diffence in seconds between UTC and the current local time zone west of UTC


ts(Object o)->Timeval

Make a timestamped object for value o with current time


ts(Timeval tv,Object o)->Timeval

Make a timestamped object for o with time point tv


usec(Timeval tv)->Integer

Microsecond in time point tv


utc_offset()->Number

Difference in seconds between UTC and the current local time zone west of UTC adjusted for daylight saving


utc_time(Timeval tv)->Charstring

Convert time point tv into ISO UTC time string


utc_time()->Charstring

The current time as ISO UTC time string


value(Timeval o)->Object

Get the value of timestamped object o