Qt linux下设置系统时间

想要能修改 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);  


Qt linux下设置系统时间,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。