Qt linux下设置系统时间

来源:互联网 发布:网络直播受众范围 编辑:程序博客网 时间:2024/05/18 12:00

想要能修改 ARM板上的系统时间,试了两种方法:

1.采用系统命令。system()

  尝试了很多命令,date -s "20090807 16:02:23" ;date -s 16:02:23 ;但板子上的日期就是设置不成功,采用date -s 16:02:23 可以将时间设置成功。于是不得不考虑别的方法。


2.标准C库

 首先感叹下,C库很强大呀!

  而且我觉着C库的移植行很好。相比较采用system()命令,可能由于linux 版本的不同,好多命令可能存在差异,比如redhat 和ubuntu 可能就存在差异。但使用C库的程序,肯定也能在redhat上运行。下面贴出源码:

 struct tm nowtime;      time_t t;     nowtime.tm_sec=56;/* Seconds.[0-60](1 leap second)*/       nowtime.tm_min=34;/* Minutes.[0-59] */       nowtime.tm_hour=12;/* Hours. [0-23] */       nowtime.tm_mday=23;/*  Day.[1-31]  */       nowtime.tm_mon=8-1;/* Month.[0-11]*/       nowtime.tm_year=2013-1900;/* Year- 1900.*/       nowtime.tm_isdst=-1;/*DST.[-1/0/1]*/       t=mktime(&nowtime);       stime(&t);  


0 0
原创粉丝点击