All Products
Search
Document Center

CDN:Time functions

Last Updated:Apr 01, 2026

EdgeScript provides the following time functions for use in CDN EdgeScript.

FunctionDescription
today()Returns the current date as a string (yyyy-mm-dd)
time()Returns the current UNIX timestamp in whole seconds
now()Returns the current UNIX timestamp with millisecond precision
localtime()Returns the current local date and time as a string (yyyy-mm-dd hh:mm:ss)
utctime()Returns the current UTC date and time as a string (yyyy-mm-dd hh:mm:ss)
cookie_time(sec)Converts a UNIX timestamp to a GMT time string in cookie format
http_time(sec)Converts a UNIX timestamp to a GMT time string in HTTP header format
parse_http_time(str)Parses an HTTP-format time string and returns the corresponding UNIX timestamp
unixtime(year, month, day, hour, min, sec)Converts a date and time to a UNIX timestamp

today

FieldDetail
Syntaxtoday()
DescriptionReturns the current date (local time) in the format yyyy-mm-dd.
ParametersNone
Return valueString — current local date in yyyy-mm-dd format

Example

say(concat('today:', today()))
# Output: today:2019-05-23

time

FieldDetail
Syntaxtime()
DescriptionReturns the current UNIX timestamp as a whole-second integer. Use now() if you need millisecond precision.
ParametersNone
Return valueInteger — current UNIX timestamp in seconds
Note

The UNIX timestamp represents the number of seconds elapsed since 00:00:00 UTC on January 1, 1970 (Unix epoch). It is independent of time zones.

Example

say(concat('time:', time()))
# Output: time:1559109666

now

FieldDetail
Syntaxnow()
DescriptionQueries the current UNIX timestamp, excluding the fractional part of milliseconds. Unit: seconds.
ParametersNone
Return valueCurrent UNIX timestamp, excluding the fractional part of milliseconds. Unit: seconds.
Note

The UNIX timestamp represents the number of seconds elapsed since 00:00:00 UTC on January 1, 1970 (Unix epoch). It is independent of time zones.

Example

say(concat('now:', now()))
# Output: now:1559109666.644

localtime

FieldDetail
Syntaxlocaltime()
DescriptionReturns the current local date and time in the format yyyy-mm-dd hh:mm:ss.
ParametersNone
Return valueString — current local date and time in yyyy-mm-dd hh:mm:ss format

Example

say(concat('localtime:', localtime()))
# Output: localtime:2019-05-29 14:02:41

utctime

FieldDetail
Syntaxutctime()
DescriptionReturns the current UTC date and time in the format yyyy-mm-dd hh:mm:ss.
ParametersNone
Return valueString — current UTC date and time in yyyy-mm-dd hh:mm:ss format

Example

say(concat('utctime:', utctime()))
# Output: utctime:2019-05-29 06:02:41

cookie_time

FieldDetail
Syntaxcookie_time(sec)
DescriptionConverts a UNIX timestamp to a GMT time string in cookie format.
Parameterssec — a UNIX timestamp (integer). Call time() to get the current timestamp.
Return valueString — GMT time string in cookie format: Wed, 29-May-19 06:02:41 GMT

Example

say(concat('cookie_time:', cookie_time(time())))
# Output: cookie_time:Wed, 29-May-19 06:02:41 GMT

http_time

FieldDetail
Syntaxhttp_time(sec)
DescriptionConverts a UNIX timestamp to a GMT time string for use in HTTP headers, such as Last-Modified.
Parameterssec — a UNIX timestamp (integer). Call time() to get the current timestamp.
Return valueString — GMT time string in HTTP-date format: Wed, 29 May 2019 06:02:41 GMT
Important

The time string is always in GMT.

Example

say(concat('http_time:', http_time(time())))
# Output: http_time:Wed, 29 May 2019 06:02:41 GMT

parse_http_time

FieldDetail
Syntaxparse_http_time(str)
DescriptionParses an HTTP-format time string and returns the corresponding UNIX timestamp. Returns false if parsing fails.
Parametersstr — a time string in the format Wed, 29 May 2019 06:02:41 GMT. Call http_time() to generate a valid input string.
Return valueInteger — UNIX timestamp if parsing succeeds; false if parsing fails
Important

This function does not handle time zone conversion. Convert the time to GMT before passing it to this function.

Examples

# Successful parse
say(concat('parse_http_time:', parse_http_time(http_time(time()))))
# Output: parse_http_time:1559109761

# Failed parse — invalid input returns false
say(concat('parse_http_time:', parse_http_time('not-a-valid-time')))
# Output: parse_http_time:false

unixtime

FieldDetail
Syntaxunixtime(year, month, day, hour, min, sec)
DescriptionConverts a date and time to a UNIX timestamp.
Parametersyear, month, day, hour, min, sec — integer values specifying the date and time components
Return valueInteger — UNIX timestamp corresponding to the specified date and time
Note

The UNIX timestamp represents the number of seconds elapsed since 00:00:00 UTC on January 1, 1970 (Unix epoch). It is independent of time zones.

Examples

t = unixtime(1970, 1, 1, 8, 0, 0)
say(concat('unixtime()=', t))
# Output: unixtime()=0

# 2021-12-23 00:00:00
t = unixtime(2021, 12, 23, 0, 0, 0)
say(concat('unixtime()=', t))
# Output: unixtime()=1640188800