set_formatted_local_time

The `set_formatted_local_time` directive sets a variable to the current local time formatted according to a specified format string.

Syntaxset_formatted_local_time name format_string;
Defaultnone
Contexthttp, server, location, if in server, if in location
Arguments2

Description

The set_formatted_local_time directive is useful for generating formatted timestamps directly within NGINX configurations. It allows you to set a variable to the current local time, formatted in a way that corresponds to the provided format string using a standard library formatting syntax (similar to strftime). This can be particularly useful for logging, caching, or other time-related configurations where the precise formatting of the timestamp is crucial.

When using this directive, you can provide two arguments: the name of the variable to set and the format string. The format string determines how the current local time will be formatted, allowing for flexibility in specifying the date and time representation. This functionality can enhance NGINX configurations by making logging or response headers more informative, ensuring that timestamps are easily readable and useful for debugging or monitoring purposes.

Config Example

set_formatted_local_time $current_time "%Y-%m-%d %H:%M:%S";

Ensure the format string is correctly specified according to the syntax of strftime.

Be cautious about time zones; this directive uses the server's local time settings.

← Back to all directives