This topic describes the syntax, description, parameters, return values, and examples of time functions.

today

This function is described as follows:
  • Syntax: today()
  • Description

    You can call this function to return the current date in the format of yyyy-mm-dd.

  • Parameters

    None

  • Return values

    This function returns the current date in the format of yyyy-mm-dd.

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

time

This function is described as follows:
  • Syntax: time()
  • Description

    You can call this function to return the current UNIX timestamp (excluding the fractional part of milliseconds), in seconds.

  • Parameters

    None

  • Return values

    This function returns the current UNIX timestamp.

  • Examples
    say(concat('time:', time()))
    
    Output:
    time:1559109666

now

This function is described as follows:
  • Syntax: now()
  • Description

    You can call this function to return the current UNIX timestamp (including the fractional part of milliseconds), in seconds.

  • Parameters

    None

  • Return values

    This function returns the current UNIX timestamp.

  • Examples
    say(concat('now:', now()))
    
    Output:
    now:1559109666.644

localtime

This function is described as follows:
  • Syntax: localtime()
  • Description

    You can call this function to return the current date and time in the format of yyyy-mm-dd hh: mm: ss.

  • Parameters

    None

  • Return values

    This function returns the current data 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

This function is described as follows:
  • Syntax: utctime()
  • Description

    You can call this function to return the current UTC time in the format of yyyy-mm-dd hh:mm:ss.

  • Parameters

    None

  • Return values

    This function returns the current UTC 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

This function is described as follows:
  • Syntax: cookie_time(sec)
  • Description

    You can call this function to generate a time string in the cookie time format from a UNIX timestamp.

  • Parameters

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

  • Return values

    This function returns the time string in the cookie time format based on the specified sec parameter.

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

http_time

This function is described as follows:
  • Syntax: http_time(sec)
  • Description

    You can call this function to generate a time string in the HTTP header time format from a UNIX timestamp. For example, the time displayed for the Last-Modified field in the HTTP header.

  • Parameters

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

  • Return values

    This function returns the time string in the HTTP header time format based on the specified sec parameter.

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

parse_http_time

This function is described as follows:
  • Syntax: parse_http_time(str)
  • Description

    You can call this function to parse the time string in the HTTP header time format and return the corresponding UNIX timestamp.

  • Parameters

    str: the time string in the HTTP header format to be parsed. For example, Thu, 22-Dec-10 10:20:35 GMT. To obtain the time string, you can call the http_time() function.

  • Return values

    This function returns the UNIX timestamp upon a success and returns false upon a failure.

  • Examples
    say(concat('parse_http_time:', parse_http_time(http_time(time()))))
    
    Output:
    parse_http_time:1559109761

unixtime

This function is described as follows:
  • Syntax: unixtime(year, month, day, hour, min, sec)
  • Description

    You can call this function to generate and return a UNIX timestamp based on the provided values of the year, month, day, hour, min, and sec parameters.

  • Parameters
    • year: specifies the year.
    • month: specifies the month.
    • day: specifies the date.
    • hour: specifies the hours.
    • min: specifies the minutes.
    • sec: specifies the seconds.
  • Return values

    This function returns the converted UNIX timestamp.

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