All Products
Search
Document Center

Server Load Balancer:Time functions

Last Updated:Apr 15, 2025

This topic describes the syntax, features, parameters, and return values of time functions and provides examples of these functions.

Click a function name to get detailed information:

today | time | now | localtime | utctime | cookie_time | http_time | parse_http_time | unixtime

today

Item

Description

Syntax

today()

Parameter

N/A

Feature

Queries the current date in the format of yyyy-mm-dd.

Return value

Example

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

Output:

today:2021-12-29

time

Item

Description

Syntax

time()

Parameter

N/A

Feature

Queries the current UNIX timestamp, excluding the fractional part of milliseconds. Unit: seconds.

Return value

Example

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

Output:

time:1559109666

now

Item

Description

Syntax

now()

Parameter

N/A

Feature

Queries the current UNIX timestamp, including the fractional part of milliseconds. Unit: seconds.

Return value

Example

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

Output:

now:1559109666.644

localtime

Item

Description

Syntax

localtime()

Parameter

N/A

Feature

Queries the current date and time in the format of yyyy-mm-dd hh:mm:ss.

Return value

Example

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

Output:

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

utctime

Item

Description

Syntax

utctime()

Parameter

N/A

Feature

Queries the current UTC time in the format of yyyy-mm-dd hh:mm:ss.

Return value

Example

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

Output:

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

cookie_time

Item

Description

Syntax

cookie_time(sec)

Parameter

sec: a UNIX timestamp. To query the UNIX timestamp, you can call the time() function.

Feature

Generates a time string that can be used in cookies based on the UNIX timestamp specified by the sec parameter.

Return value

Example

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

Output:

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

http_time

Item

Description

Syntax

http_time(sec)

Parameter

sec: a UNIX timestamp. To query the UNIX timestamp, you can call the time() function.

Feature

Generates a time string that can be used in HTTP headers. For example, a time string that can be used in the Last-Modified header.

Return value

A time string that can be used in HTTP headers based on the UNIX timestamp specified by the sec parameter.

Example

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

Output

http_time:Wed, 29 Dec 2021 06:02:41 GMT

parse_http_time

Item

Description

Syntax

parse_http_time(str)

Parameter

str: the time string that you want to parse. Example: Thu, 22-Dec-10 10:20:35 GMT. To query the time string, you can call the http_time() function.

Feature

Parses a time string that can be used in HTTP headers and returns the corresponding UNIX timestamp.

Return value

If the function succeeds, a UNIX timestamp is returned. If the function fails, false is returned.

Example

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

Output

parse_http_time:1559109761

unixtime

Item

Description

Syntax

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

Parameter

  • year

  • month

  • day

  • hour

  • min

  • sec

Feature

Generates and returns a UNIX timestamp based on the provided values of the year, month, day, hour, min, and sec parameters.

Return value

Example

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

Output

UNIXtime()=0