$time_iso8601

The variable $time_iso8601 returns the current time in ISO 8601 format. — NGINX Core (HTTP)

$time_iso8601 NGINX Core (HTTP)

Description

The $time_iso8601 variable outputs the date and time in a format that complies with the ISO 8601 standard. This timestamp is typically formatted as 'YYYY-MM-DDTHH:MM:SS+ZONE', which for example corresponds to '2023-10-04T12:34:56+00:00'. The variable is populated by NGINX during the processing of a request and is available across various contexts within a configuration file. It leverages the server's local time zone settings to ensure that the displayed time aligns with the server's current time settings. It is particularly useful for logging purposes or in the context of HTTP headers, where an unambiguous representation of the date and time can aid in client interpretation, debugging and data analytics. Typically, NGINX sets this variable each time a request is processed, ensuring that it is up-to-date when accessed during the request lifecycle. As part of the timestamp output, it incorporates timezone information, making it suitable for scenarios where timezone variance is a consideration. Due to its standard format, $time_iso8601 is favored in RESTful API responses and web services that require precise timestamps, as it allows clients to interpret the received data accurately across different timezones. The variable can be formatted in the same manner as traditional date command formats in NGINX, maintaining its usability across various installation environments.

Config Example

http {
    log_format combined '$remote_addr - $remote_user [$time_iso8601] "$request" '
                  '$status $body_bytes_sent "$http_referer" "$http_user_agent"';
    access_log /var/log/nginx/access.log combined;
}

Subsystem

http

Cacheable

No

Contexts

http, server, location, if

Ensure the server's timezone is set correctly, as this affects the output of $time_iso8601.

$time_iso8601 does not change once assigned in a specific request; it remains the same throughout the request handling process.