QT下设置Linux系统时间

来源:互联网 发布:红帽系统yum源 编辑:程序博客网 时间:2024/05/29 16:13
在嵌入式应用中,一般具有设置系统时间的功能,以下代码可设置系统时间:bool set_date_time(const QDateTime &dateTime){    /* 更新系统时间 */    struct timeval tv;    struct timezone tz;    if(0 == gettimeofday(&tv, &tz)) {        tv.tv_sec   = dateTime.toTime_t();        tv.tv_usec  = 0;        if(0 == settimeofday(&tv, &tz)) {            system("hwclock -w");   /* 系统时间同步到硬件时钟 */            return  true;        }    }    return false;}


原创粉丝点击