阅读:1809回复:2
在linux或dos下如何通过程序修改系统时间呢?
修改系统时间时:
int settimeofday(const struct timeval *tv,const struct timezone *tz); 这个函数中的第一个参数的结构timeval中是秒或者是毫秒, 我如何才能把2002年5月3日12时24分36秒转成timeval的结构呢? |
|
沙发#
发布于:2002-10-28 13:26
靠,还真漏了
time_t *td; struct tm s_time; s_time.tm_hour = 12; // 12点 s_time.tm_min = 24 //24分 s_time.tm_sec = 36; //36秒 s_time.year = 2002-1900; // Linux从1900年计算 s_time.mon = 5; //5月 s_time.day = 3; //3 日 td = mktime(&s_time); stime(td);//设置时间 |
|
板凳#
发布于:2002-10-26 20:20
偶来回答,如有疏漏请各位大虾多多指教
time_t td; struct tm s_time; s_time.tm_hour = 12; // 12点 s_time.tm_min = 24 //24分 s_time.tm_sec = 36; //36秒 s_time.year = 2002-1900; // Linux从1900年计算 s_time.mon = 5; //5月 s_time.day = 3; //3 日 stime(&td);//设置时间 |
|