时间戳与时间的相互转化,数据不对
时间戳1384936600对应的时间是2013-11-20-8:36:40 可是输出的是2013-11-20-3-36-40
时间2013-11-20-8:36:40对应的时间戳是1384936600,可是输出的是1384951000
不知道错在哪里
//时间转化成时间戳
long timeChange(stTIME_INFO* data){
time_t timep;
struct tm p;
p.tm_year=2013-1900;
p.tm_mon=11-1;
p.tm_mday=20;
p.tm_hour=8;
p.tm_min=36;
p.tm_sec=40;
/*p.tm_year=data->tm_year-1900;
p.tm_mon=data->tm_mon-1;
p.tm_mday=data->tm_mday;
p.tm_hour=data->tm_hour;
p.tm_min=data->tm_min;
p.tm_sec=data->tm_sec;*/
timep=mktime(&p);
printf("time%d\n",timep);
return timep;
}
//时间戳转化成时间
int stampChange(time_t timep,stTIME_INFO* data){
struct tm *p;
timep=1384936600;
printf("pppppstamp:%d\n",timep);
p=localtime(&timep);
data->tm_year =p->tm_year+1900;
data->tm_mon =1+p->tm_mon;
data->tm_mday = p->tm_mday;
data->tm_hour =p->tm_hour;
data->tm_min =p->tm_min;
data->tm_sec =p->tm_sec;
data->tm_msec = 0;
printf("%d-%d-%d-%d-%d-%d\n",data->tm_year,data->tm_mon,data->tm_mday,data->tm_hour,data->tm_min,data->tm_sec);
timeChange(data);
return 0;
}