11.5. Time and Date Functions

Several API calls give you access to Apache's routines for formatting and parsing HTTP-compliant date strings. Also see the descriptions for ap_update_mtime( ) and ap_set_last_modified( ) in Section 10.6.4, under Section 10.6.4."

The declarations for these functions are scattered among several header files, including httpd.h, util_date.h, and http_request.h. In the following list we indicate where the function can be found:

char *ap_ht_time (pool *p, time_t t, const char *fmt, int gmt)

(Declared in the header file httpd.h.) Given a resource pool, a time_t timestamp, a character format, and a flag indicating whether or not to use GMT (Greenwich Mean Time, also known as Universal Standard Time), this function returns a character string containing the date. The character format uses the same code as the standard C library strftime() function, with the addition of two common extensions. The code %Z is substituted with the string GMT, and the code %z is substituted with +0000. See the manual page for strftime() for other codes you can use.

This example returns a string in the format Tue, 15 Sep 1998 14:36:31 GMT, which happens to be the HTTP date format recommended by RFCs 822 and 1123.

char *str = ap_ht_time(p, time(NULL), "%a %d %b %Y %T %Z", 0);

time_t ap_parseHTTPdate (const char *date)

(Declared in the header file util_date.c.) Given a char* containing a date in HTTP format, this routine parses the date and returns a time_t Unix timestamp. This ...

Get Writing Apache Modules with Perl and C now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.