RFC1123 defines a number of things, among them, the format of Dates to be used in internet protocols. HTTP (RFC2616) specifies that date formats must be generated in conformance with RFC1123.
It looks like this:
Date: Wed, 28 Apr 2010 02:31:05 GMT
How can I generate an RFC1123 time string from C code, running on Windows? I don't have the use of C# and DateTime.ToString().
I know I could write the code myself, to emit timezones and day abbreviations, but I'm hoping this already exists in the Windows API.
Thanks.
This is what I used:
static const char *DAY_NAMES[] =
{ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
static const char *MONTH_NAMES[] =
{ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
char *Rfc1123_DateTimeNow()
{
const int RFC1123_TIME_LEN = 29;
time_t t;
struct tm tm;
char * buf = malloc(RFC1123_TIME_LEN+1);
time(&t);
gmtime_s(&tm, &t);
strftime(buf, RFC1123_TIME_LEN+1, "---, %d --- %Y %H:%M:%S GMT", &tm);
memcpy(buf, DAY_NAMES[tm.tm_wday], 3);
memcpy(buf+8, MONTH_NAMES[tm.tm_mon], 3);
return buf;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With