您的位置:首页 > 运维架构 > Linux

QT下设置Linux系统时间

2017-11-10 16:28 357 查看
在嵌入式应用中,一般具有设置系统时间的功能,以下代码可设置系统时间:

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  qt 嵌入式 应用 linux