我写了下面的代码将日期转换为时间戳。转换日期为时代忽略系统时区
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
int main()
{
struct tm date_time;
char date_time_buf[255];
char date_time_hdr[255]={0};
strncpy(date_time_hdr,"Thu, 02 Mar 2017 05:54:28 GMT",255);
memset(&date_time, 0, sizeof(struct tm));
strptime(date_time_hdr, "%a, %d %b %Y %H:%M:%S %Z", &date_time);
memset(date_time_buf, 0, 255);
strftime(date_time_buf, 255, "%s", &date_time);
int p=atoi(date_time_buf);
printf("time is %d \r\n", p);
return 0;
}
我可以将日期转换为时间戳。但面临一个问题。 时间戳由5小时30分钟偏移,这是我的Linux机器的时区。但我不想那样。有没有办法忽略系统时区?
由于您使用的是POSIX.1 ['strptime()'](http://man7.org/linux/man-pages/man3/strptime.3.html),您应该添加'posix'标签对你的问题! –