All Products
Search
Document Center

Server Load Balancer:Time functions

Last Updated:Apr 01, 2026

This topic describes nine built-in time functions for reading timestamps, formatting time strings for HTTP and cookie headers, and converting between time representations.

FunctionReturnsDescription
today()StringCurrent date in yyyy-mm-dd format (local time)
time()IntegerCurrent UNIX timestamp in seconds, without milliseconds
now()FloatCurrent UNIX timestamp in seconds, with milliseconds
localtime()StringCurrent date and time in yyyy-mm-dd hh:mm:ss format (local time)
utctime()StringCurrent date and time in yyyy-mm-dd hh:mm:ss format (UTC)
cookie_time(sec)StringFormats a UNIX timestamp as a cookie-compatible time string
http_time(sec)StringFormats a UNIX timestamp as an HTTP header time string
parse_http_time(str)Integer or falseParses an HTTP time string and returns its UNIX timestamp
unixtime(year, month, day, hour, min, sec)IntegerConstructs a UNIX timestamp from date and time components

today

str = today()

Returns the current date as a string in yyyy-mm-dd format. This is the local time of the server.

Parameters: None

Example:

say(concat('today:', today()))

Output:

today:2021-12-29

time

secs = time()

Returns the current UNIX timestamp as an integer (seconds since the Unix epoch), without the millisecond fractional part.

Parameters: None

Example:

say(concat('time:', time()))

Output:

time:1559109666
To get sub-second precision, use now() instead.

now

secs = now()

Returns the current UNIX timestamp as a floating-point number, including milliseconds as the decimal part.

Parameters: None

Example:

say(concat('now:', now()))

Output:

now:1559109666.644

localtime

str = localtime()

Returns the current date and time as a string in yyyy-mm-dd hh:mm:ss format. This is the local time of the server.

Parameters: None

Example:

say(concat('localtime:', localtime()))

Output:

localtime:2021-12-29 14:02:41

utctime

str = utctime()

Returns the current date and time as a string in yyyy-mm-dd hh:mm:ss format. This is UTC time.

Parameters: None

Example:

say(concat('utctime:', utctime()))

Output:

utctime:2021-12-29 06:02:41

cookie_time

str = cookie_time(sec)

Formats a UNIX timestamp as a time string suitable for use in HTTP cookies.

Parameters:

ParameterTypeDescription
secIntegerA UNIX timestamp in seconds. Call time() to get the current timestamp.

Example:

say(concat('cookie_time:', cookie_time(time())))

Output:

cookie_time:Wed, 29-Dec-21 06:02:41 GMT

http_time

str = http_time(sec)

Formats a UNIX timestamp as a time string suitable for use in HTTP headers such as Last-Modified.

Parameters:

ParameterTypeDescription
secIntegerA UNIX timestamp in seconds. Call time() to get the current timestamp.

Example:

say(concat('http_time:', http_time(time())))

Output:

http_time:Wed, 29 Dec 2021 06:02:41 GMT
cookie_time and http_time produce different formats from the same timestamp. cookie_time uses dashes and a two-digit year (29-Dec-21), while http_time uses spaces and a four-digit year (29 Dec 2021).

parse_http_time

sec = parse_http_time(str)

Parses an HTTP-formatted time string and returns the corresponding UNIX timestamp.

Parameters:

ParameterTypeDescription
strStringAn HTTP-formatted time string such as Thu, 22-Dec-10 10:20:35 GMT. Call http_time() to generate a valid input.

Return value: The UNIX timestamp as an integer if parsing succeeds, or false if the input string is malformed.

Example:

say(concat('parse_http_time:', parse_http_time(http_time(time()))))

Output:

parse_http_time:1559109761

unixtime

secs = unixtime(year, month, day, hour, min, sec)

Constructs a UNIX timestamp from the specified date and time components.

Parameters:

ParameterTypeDescription
yearIntegerFour-digit year
monthIntegerMonth
dayIntegerDay of the month
hourIntegerHour
minIntegerMinute
secIntegerSecond

Return value: The UNIX timestamp corresponding to the specified date and time.

Example:

t = UNIXtime(1970, 1, 1, 8, 0, 0)
say(concat('UNIXtime()=', t))

Output:

UNIXtime()=0