# HG changeset patch # User Vladimir Homutov # Date 1493731533 -10800 # Node ID 28ee7ab54a90ae90ffa01faf0a6d80976c63eac9 # Parent 082724c57c381734d6dabaf08beddd233dda959b Added the "Time" section to the development guide. diff -r 082724c57c38 -r 28ee7ab54a90 xml/en/docs/dev/development_guide.xml --- a/xml/en/docs/dev/development_guide.xml Thu Apr 27 18:11:49 2017 +0300 +++ b/xml/en/docs/dev/development_guide.xml Tue May 02 16:25:33 2017 +0300 @@ -652,6 +652,108 @@ +
+ + +The ngx_time_t structure represents time split into seconds +and milliseconds with specification of GMT offset: + +typedef struct { + time_t sec; + ngx_uint_t msec; + ngx_int_t gmtoff; +} ngx_time_t; + +The ngx_tm_t is an alias for struct tm +on UNIX platforms and SYSTEMTIME on Windows. + + + +To obtain current time, usually it is enough to access one of available global +variables, representing the cached time value in desired format. +The ngx_current_msec variable holds milliseconds elapsed +since Epoch and truncated to ngx_msec_t. + + + +Available string representations are: + + + + +ngx_cached_err_log_time — used in error log: +"1970/09/28 12:00:00" + + + +ngx_cached_http_log_time — used in HTTP access log: +"28/Sep/1970:12:00:00 +0600" + + + +ngx_cached_syslog_time — used in syslog: +"Sep 28 12:00:00" + + + +ngx_cached_http_time — used in HTTP for headers: +"Mon, 28 Sep 1970 06:00:00 GMT" + + + +ngx_cached_http_log_iso8601 — in the ISO 8601 +standard format: +"1970-09-28T12:00:00+06:00" + + + + + + +The ngx_time() and ngx_timeofday() macros +returning current value of seconds are a preferred way to access cached +time value. + + + +To obtain the time explicitly, ngx_gettimeofday() may +be used, which updates its argument (pointer to +struct timeval). +Time is always updated when nginx returns to event loop from system calls. +To update the time immediately, call ngx_time_update(), +or ngx_time_sigsafe_update() if you need it in the +signal handler context. + + + +The following functions convert time_t into broken-down time +representation, either ngx_tm_t or +struct tm for those with libc prefix: + + + + +ngx_gmtime(), ngx_libc_gmtime() — result time is UTC + + + +ngx_localtime(), ngx_libc_localtime() — result time is +relative to the timezone + + + + +The ngx_http_time(buf, time) returns string +representation suitable for use with HTTP headers (for example, +"Mon, 28 Sep 1970 06:00:00 GMT"). +Another possible conversion is provided by +ngx_http_cookie_time(buf, time) that produces format suitable +for HTTP cookies ("Thu, 31-Dec-37 23:55:55 GMT"). + + +
+ +