python localtime 与utc时间差5分钟_在linux中用localtime()显示的时间与实际时间不相符,不是与北京时间差8个小时,而是差15个小时...
为方便调试程序,输入数据我用了空格。
#include
#include
void main(){
struct tm *ptm;
time_t rawtime, t;
int year,month,mday,hh,mm,ss;
time ( &rawtime );
ptm = gmtime ( &rawtime ); //建 UTC 时间
printf("Please enter year month day hour minute second\n");
printf("For example: \n");
printf("2013 2 28 23 35 4\n");
scanf("%d %d %d %d %d %d", &year, &month, &mday, &hh,&mm,&ss);
ptm->tm_year = year - 1900;
ptm->tm_mon= month - 1;
ptm->tm_mday = mday ;
ptm->tm_hour = hh ;
ptm->tm_min = mm ;
ptm->tm_sec = ss ;
t = mktime (ptm); //得 UTC 时间 年月日时分秒
printf("%s ",ctime(&t)); // 打印出 Thu Feb 28 23:35:04 2013
t = t+8*3600; //北京时间,加 8 小时就是
printf("%s ",ctime(&t)); // 打印出 Fri Mar 01 07:35:04 2013
}
// MS VC++ 6.0 编译器
取消
评论
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
