0
我想在Windows C++中将Unix Epoch时间转换为PST,但我的代码在转换时间为03/09/2014 10:00时失败。该计划首先将时代转换为格林尼治标准时间,然后从格林威治标准时间减去8小时,但对于2014年9月3日10:00时间戳,它将产生03/09/2014 01:00而不是03/09/2014 02:00。我正在使用Visual syudi 6.0版本。如何将Unix Epoch时间转换为Windows C++中的PST?
我可以知道我的代码错在哪里吗?
#include "stdafx.h"
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include<ctime>
int main(int argc, char *argv[])
{
struct tm * ptm;
time_t rawtime = 1394359200; // 03/09/2014 10:00
// -- convert UNIX timestamp to GMT time
ptm = gmtime (&rawtime);
printf("\nBEFORE CONVERSION = %04d %02d %02d %02d %02d\n",ptm->tm_year+1900,(ptm- >tm_mon)+1,ptm->tm_mday,ptm->tm_hour,ptm->tm_min);
// -- Substract 8 hours from GMT time
ptm->tm_hour = (ptm->tm_hour) - 8;
// -- Make time after substaction
mktime (ptm);
printf("\nAFTER CONVERSION = %04d %02d %02d %02d %02d\n",ptm->tm_year+1900,(ptm->tm_mon)+1,ptm->tm_mday,ptm->tm_hour,ptm->tm_min);
return 0;
}
在此先感谢您的帮助。