Qt设置系统时间
2012-10-27 13:32
337 查看
读取系统时间
[cpp]
void moreidDialog::refresh_time()
{
QDateTime time;
txt_time->setText(time.currentDateTime().toString("yyyy") + "." + \
time.currentDateTime().toString("M") + "." + \
time.currentDateTime().toString("d") + "." + \
time.currentDateTime().toString("h") + "." + \
time.currentDateTime().toString("m"));
}
读取到分,时间间隔用".",最终读取并显示的效果:2011.12.27.9.14
设置系统时间
[cpp]
//保存时间键
void moreidDialog::slot_save_time_key()
{
QDateTime time;
QString str = txt_time->text();
//判断格式是否正确
if (str.count(".") != 4)
{
txt_time->setText(tr("ge shi cuo wu"));
return;
}
int i = 0,j = 0;
i = str.indexOf(".");
QString year = str.mid(0,i);
j = str.indexOf(".",i + 1);
QString month = str.mid(i + 1,j - i - 1);
i = j;
j = str.indexOf(".",i + 1);
QString day = str.mid(i + 1,j - i - 1);
i = j;
j = str.indexOf(".",i + 1);
QString hour = str.mid(i + 1,j - i - 1);
i = j;
j = str.indexOf(".",i + 1);
QString min = str.mid(i + 1,j - i - 1);
bool ok = false;
year.toInt(&ok);
if (ok == false)
{
txt_time->setText(tr("ge shi cuo wu"));
return;
}
month.toInt(&ok);
if (ok == false)
{
txt_time->setText(tr("ge shi cuo wu"));
return;
}
day.toInt(&ok);
if (ok == false)
{
txt_time->setText(tr("ge shi cuo wu"));
return;
}
hour.toInt(&ok);
if (ok == false)
{
txt_time->setText(tr("ge shi cuo wu"));
return;
}
min.toInt(&ok);
if (ok == false)
{
txt_time->setText(tr("ge shi cuo wu"));
return;
}
//str = "date -s " + month + "/" + day + "/" + year;
// system(str.toLatin1().data());
// str = "date -s " + hour + ":" + min + ":" + "00";
// system(str.toLatin1().data());
str = "date -s " + month + day +hour+min+"00"+ year;//SBC8100上测试用通过
system(str.toLatin1().data());
//强制写入到CMOS
system("clock -w");
}
同步系统时钟与硬件时钟时间命令:
硬件时钟同步到系统时钟:hwclock --hctosys
系统时钟同步到硬件时钟:hwclock -systohc
[cpp]
void moreidDialog::refresh_time()
{
QDateTime time;
txt_time->setText(time.currentDateTime().toString("yyyy") + "." + \
time.currentDateTime().toString("M") + "." + \
time.currentDateTime().toString("d") + "." + \
time.currentDateTime().toString("h") + "." + \
time.currentDateTime().toString("m"));
}
读取到分,时间间隔用".",最终读取并显示的效果:2011.12.27.9.14
设置系统时间
[cpp]
//保存时间键
void moreidDialog::slot_save_time_key()
{
QDateTime time;
QString str = txt_time->text();
//判断格式是否正确
if (str.count(".") != 4)
{
txt_time->setText(tr("ge shi cuo wu"));
return;
}
int i = 0,j = 0;
i = str.indexOf(".");
QString year = str.mid(0,i);
j = str.indexOf(".",i + 1);
QString month = str.mid(i + 1,j - i - 1);
i = j;
j = str.indexOf(".",i + 1);
QString day = str.mid(i + 1,j - i - 1);
i = j;
j = str.indexOf(".",i + 1);
QString hour = str.mid(i + 1,j - i - 1);
i = j;
j = str.indexOf(".",i + 1);
QString min = str.mid(i + 1,j - i - 1);
bool ok = false;
year.toInt(&ok);
if (ok == false)
{
txt_time->setText(tr("ge shi cuo wu"));
return;
}
month.toInt(&ok);
if (ok == false)
{
txt_time->setText(tr("ge shi cuo wu"));
return;
}
day.toInt(&ok);
if (ok == false)
{
txt_time->setText(tr("ge shi cuo wu"));
return;
}
hour.toInt(&ok);
if (ok == false)
{
txt_time->setText(tr("ge shi cuo wu"));
return;
}
min.toInt(&ok);
if (ok == false)
{
txt_time->setText(tr("ge shi cuo wu"));
return;
}
//str = "date -s " + month + "/" + day + "/" + year;
// system(str.toLatin1().data());
// str = "date -s " + hour + ":" + min + ":" + "00";
// system(str.toLatin1().data());
str = "date -s " + month + day +hour+min+"00"+ year;//SBC8100上测试用通过
system(str.toLatin1().data());
//强制写入到CMOS
system("clock -w");
}
同步系统时钟与硬件时钟时间命令:
硬件时钟同步到系统时钟:hwclock --hctosys
系统时钟同步到硬件时钟:hwclock -systohc
相关文章推荐
- qt4 设置系统日期 时间,set time date, set system date time
- 【转】QT获取系统时间,以及设置日期格式
- Qt中设置win7的系统时间
- Qt设置系统时间
- Qt中设置系统时间,调用system()函数
- QT获取系统时间以及设置日期格式
- QT在linux环境下读取和设置系统时间(通过system来直接调用Linux命令,注意权限问题)
- QT在linux环境下读取和设置系统时间
- 周报——QT可设置系统时间
- Qt4 设置系统日期时间
- qt4 设置系统日期 时间,set time date, set system date time
- QT获取系统时间,以及设置日期格式
- QT 设置系统时间
- QT下设置Linux系统时间
- QT——设置窗口的固定大小、QProcess、定时器事件、QString::arg、系统时间、QPixmap 和 QImage 区别
- QT获取系统时间,以及设置日期格式
- QT修改、获取系统时间,以及设置日…
- QT 设置系统时间
- Qt设置系统时间(使用SetSystemTime API函数)
- QT获取系统时间,以及设置日期格式