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.
Item | Description |
---|---|
Syntax | today()
|
Description | Queries the current date (local time) in the format of yyyy-mm-dd. |
Parameters | None |
Return value | Returns the current date in the format of yyyy-mm-dd. |
Examples | Output:
|
time
The following table describes the details about this function.
Item | Description |
---|---|
Syntax | time()
|
Description | Queries 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.
|
Parameters | None. |
Return value | Returns the current UNIX timestamp. |
Examples | Output:
|
now
The following table describes the details about this function.
Item | Description |
---|---|
Syntax | now()
|
Description | Queries 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.
|
Parameters | None. |
Return value | Returns the current UNIX timestamp, excluding the fractional part of milliseconds. Unit: seconds. |
Examples | The following result is returned:
|
localtime
The following table describes the details about this function.
Item | Description |
---|---|
Syntax | localtime()
|
Description | Queries the current date and time (local time) in the format of yyyy-mm-dd hh:mm:ss. |
Parameters | None. |
Return value | Returns the current date and time in the format of yyyy-mm-dd hh:mm:ss. |
Examples | Output:
|
utctime
The following table describes the details about this function.
Item | Description |
---|---|
Syntax | utctime()
|
Description | Queries the current UTC time in the format of yyyy-mm-dd hh:mm:ss. |
Parameters | None. |
Return value | Queries the current date and time in the format of yyyy-mm-dd hh:mm:ss. |
Examples | Output:
|
cookie_time
The following table describes the details about this function.
Item | Description |
---|---|
Syntax | cookie_time(sec)
|
Description | Generates a GMT time string in the cookie format. |
Parameters | sec: a UNIX timestamp. To query the UNIX timestamp, you can call the time() function.
|
Return value | Returns a time string that can be used in cookies based on the UNIX timestamp specified
by the sec parameter.
|
Examples | Output:
|
http_time
The following table describes the details about this function.
Item | Description |
---|---|
Syntax | http_time(sec)
|
Description | Generates 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.
Notice Time strings generated by this function are in GMT.
|
Parameters | sec: a UNIX timestamp. To query the UNIX timestamp, you can call the time() function.
|
Return value | Returns a time string that can be used in HTTP headers based on the UNIX timestamp
specified by the sec parameter.
|
Examples | Output:
|
parse_http_time
The following table describes the details about this function.
Item | Description |
---|---|
Syntax | parse_http_time(str)
|
Description | Parses a time string that is used in HTTP headers and returns the corresponding UNIX
timestamp.
Notice This function does not recognize time zones. You must convert the local time to GMT
before you pass the time to this function.
|
Parameters | str: 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 value | If the function succeeds, a UNIX timestamp is returned. Otherwise, false is returned.
|
Examples | Output:
|
unixtime
The following table describes the details about this function.
Item | Description |
---|---|
Syntax | Syntax: unixtime(year, month, day, hour, min, sec) .
|
Description | Generates 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 |
|
Return value | Returns a UNIX timestamp. |
Examples |
|