2

In nginx configuration file, what is the best way to get a variable containing string representation of current time in seconds since epoch? Conceptually I want something like this:

$timestamp = <unix_time>;
add_header Time $timestamp;

As requested by a moderator, this is not a duplication of

Is there a way to get the current time in nginx?

as variables $date_gmt and $date_local do not provide seconds-since-epoch format.

wick
  • 1,995
  • 2
  • 20
  • 31
  • 1
    Possible duplicate of [Is there a way to get the current time in nginx?](https://stackoverflow.com/questions/10789194/is-there-a-way-to-get-the-current-time-in-nginx) – mrbm Sep 22 '18 at 12:46

2 Answers2

5

As per the docs, it's in the $msec variable.

miknik
  • 5,748
  • 1
  • 10
  • 26
1

In fact, the functionality was added to this module:

https://github.com/openresty/set-misc-nginx-module

Sought line would be:

set_formatted_gmt_time $unix_time_str "%s";

wick
  • 1,995
  • 2
  • 20
  • 31