开发者

Convert RFC 822 timestamp to unixtime, timezone values not working , C/C++

开发者 https://www.devze.com 2023-02-12 00:07 出处:网络
I\'ve a function which converts an RFC 822 timestamp to unixtime #include <stdio.h> #include <time.h>

I've a function which converts an RFC 822 timestamp to unixtime

#include <stdio.h>
#include <time.h>

int main() {

struct tm tm;
time_t unixtime;

strptime("Sun, 20 Feb 2011 10:28:02 +0800","%a, %e %h %Y %H:%M:%S %z",&tm);

unixtime = mktime(&tm);
printf("%d\n",unixtime);

return 0;
}

Problem: The timezone part (%z) doesn't seem to be working. I tried changing input timezone to other values +0100, + 0200 ect without changing other date values, it always gives the same unixtime stamp (ie, unixtimestamp corresponding to GMT)

Wh开发者_JAVA技巧at can be the issue here ?


struct tm does not contain a timezone field. %z is supported simply to support the same flags as strftime. You'll need to extract and adjust the timezone offset manually.

0

精彩评论

暂无评论...
验证码 换一张
取 消