Name: Anonymous 2012-10-12 16:52
Hey /prog/,
Making a program dealing with RFC2822 dates. Can you guys compile & run the following and advise if it's the correct timezone.
You time is much appreciated.
Making a program dealing with RFC2822 dates. Can you guys compile & run the following and advise if it's the correct timezone.
You time is much appreciated.
#ifdef _WIN32
#define __MSVCRT_VERSION__ 0x0601
#include <windows.h>
#endif
#include <time.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
#ifndef _WIN32
time_t RawTime;
#else
__time64_t RawTime;
#endif
struct tm GMT, Local, *TimeInfo;
const char *Days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
const char *Months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
RawTime =
#ifndef _WIN32
time(NULL);
#else
_time64(NULL);
#endif
if (RawTime == -1)
return 1;
TimeInfo =
#ifndef _WIN32
gmtime(&RawTime);
#else
(struct tm *)_gmtime64(&RawTime);
#endif
GMT = *TimeInfo;
TimeInfo =
#ifndef _WIN32
localtime(&RawTime);
#else
(struct tm *)_localtime64(&RawTime);
#endif
Local = *TimeInfo;
if (Local.tm_hour > 12)
GMT.tm_hour += 24;
if (Local.tm_isdst > 0)
GMT.tm_hour += 2;
printf("%s, %.2d %s %d %.2d:%.2d:%.2d %+03i00",
Days[Local.tm_wday], Local.tm_mday, Months[Local.tm_mon], Local.tm_year + 1900,
Local.tm_hour, Local.tm_min, Local.tm_sec,
GMT.tm_hour - Local.tm_hour);
return 0;
}