windows下的修改系统时间
void UIManager::setSysTime()
{
//#include <windows.h>
//#include <stdlib.h>
SYSTEMTIME s;
//GetLocalTime(&s); //SetLocalTime(&s)
//GetSystemTime()获取的格林尼治时间, 是全球标准时间。SetSystemTime(&s)
s.wYear=2000+temp[0]*10+temp[1];
s.wMonth=temp[2]*10+temp[3];
s.wDay=temp[4]*10+temp[5];
s.wHour=temp[6]*10+temp[7];
s.wMinute=temp[8]*10+temp[9];
if(SetLocalTime(&s))
cout<<"setting time is success"<<endl;
else
cout<<"setting time is not success"<<endl;
}
linux下的修改系统时间
void UIManager::SetHwColock(string dateTime)
{
string d="sudo date -s '"+dateTime+"'";//要输入密码,在板子上去掉sudo
system(d.c_str());
system("sudo hwclock --systohc");//要输入密码,在板子上去掉sudo
//system("sudo hwclock");//验证是否修改成功
}
本文介绍了如何在Windows和Linux环境下通过编程方式修改系统时间的方法。Windows下使用SetLocalTime函数,而Linux则利用date命令结合sudo权限进行设置,并通过hwclock命令同步到硬件时钟。
479

被折叠的 条评论
为什么被折叠?



