All Products
Search
Document Center

CDN:Time functions

Last Updated:Oct 14, 2024

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

today

The following table describes the details about this function.
ItemDescription
Syntaxtoday()
DescriptionQueries the current date (local time) in the format of yyyy-mm-dd.
ParametersNone
Return valueReturns the current date in the format of yyyy-mm-dd.
Examples
say(concat('today:', today()))
Output:
today:2019-05-23

time

The following table describes the details about this function.
ItemDescription
Syntaxtime()
DescriptionQueries the current UNIX timestamp, excluding the fractional part of milliseconds. Unit: seconds.
Note The UNIX timestamp is irrelevant to time zones, and indicates the number of seconds that have elapsed since 00:00:00 (UTC or GMT) on January 1, 1970.
ParametersNone.
Return valueReturns the current UNIX timestamp.
Examples
say(concat('time:', time()))
Output:
time:1559109666

now

The following table describes the details about this function.
ItemDescription
Syntaxnow()
DescriptionQueries the current UNIX timestamp, excluding the fractional part of milliseconds. Unit: seconds.
Note The UNIX timestamp is irrelevant to time zones, and indicates the number of seconds that have elapsed since 00:00:00 (UTC or GMT) on January 1, 1970.
ParametersNone.
Return valueReturns the current UNIX timestamp, excluding the fractional part of milliseconds. Unit: seconds.
Examples
say(concat('now:', now()))
The following result is returned:
now:1559109666.644

localtime

The following table describes the details about this function.
ItemDescription
Syntaxlocaltime()
DescriptionQueries the current date and time (local time) in the format of yyyy-mm-dd hh:mm:ss.
ParametersNone.
Return valueReturns the current date and time in the format of yyyy-mm-dd hh:mm:ss.
Examples
say(concat('localtime:', localtime()))
Output:
localtime:2019-05-29 14:02:41

utctime

The following table describes the details about this function.
ItemDescription
Syntaxutctime()
DescriptionQueries the current UTC time in the format of yyyy-mm-dd hh:mm:ss.
ParametersNone.
Return valueQueries the current date and time in the format of yyyy-mm-dd hh:mm:ss.
Examples
say(concat('utctime:', utctime()))
Output:
utctime:2019-05-29 06:02:41

cookie_time

The following table describes the details about this function.
ItemDescription
Syntaxcookie_time(sec)
DescriptionGenerates a GMT time string in the cookie format.
Parameterssec: a UNIX timestamp. To query the UNIX timestamp, you can call the time() function.
Return valueReturns a time string that can be used in cookies based on the UNIX timestamp specified by the sec parameter.
Examples
say(concat('cookie_time:', cookie_time(time())))
Output:
cookie_time:Wed, 29-May-19 06:02:41 GMT

http_time

The following table describes the details about this function.
ItemDescription
Syntaxhttp_time(sec)
DescriptionGenerates a time string that can be used in HTTP headers based on a UNIX timestamp. For example, you can call this function to generate a time string that can be used in the Last-Modified header.
Important Time strings generated by this function are in GMT.
Parameterssec: a UNIX timestamp. To query the UNIX timestamp, you can call the time() function.
Return valueReturns a time string that can be used in HTTP headers based on the UNIX timestamp specified by the sec parameter.
Examples
say(concat('http_time:', http_time(time())))
Output:
http_time:Wed, 29 May 2019 06:02:41 GMT

parse_http_time

The following table describes the details about this function.
ItemDescription
Syntaxparse_http_time(str)
DescriptionParses a time string that is used in HTTP headers and returns the corresponding UNIX timestamp.
Important This function does not recognize time zones. You must convert the local time to GMT before you pass the time to this function.
Parametersstr: the time string that you want to parse. Format: Wed, 29 May 2019 06:02:41 GMT. To query the time string, you can call the http_time() function.
Return valueIf the function succeeds, a UNIX timestamp is returned. Otherwise, false is returned.
Examples
say(concat('parse_http_time:', parse_http_time(http_time(time()))))
Output:
parse_http_time:1559109761

unixtime

The following table describes the details about this function.
ItemDescription
SyntaxSyntax: unixtime(year, month, day, hour, min, sec).
DescriptionGenerates and returns a UNIX timestamp based on the provided values of the year, month, day, hour, min, and sec parameters.
Note The UNIX timestamp is irrelevant to time zones, and indicates the number of seconds that have elapsed since 00:00:00 (UTC or GMT) on January 1, 1970.
Parameters
  • year: specifies the year.
  • month: specifies the month.
  • day: specifies the day.
  • hour: specifies the hour.
  • min: specifies the minute.
  • sec: specifies the second.
Return valueReturns a UNIX timestamp.
Examples
  • Example 1:
    t = unixtime(1970, 1, 1, 8, 0, 0)
    say(concat('unixtime()=', t))

    Output:

    unixtime()=0
  • Example 2:
    t = unixtime(2021,12,23,0,0,0)
    say(concat('unixtime()=', t))

    Output:

    unixtime()=1640188800