为方便调试程序,输入数据我用了空格。
#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 编译器