1、使用命令设置时间
1)date -s
常用格式:
date -s “yyyyMMdd hh:mm:ss”
date -s “yyyy-MM-dd hh:mm:ss”
2)hwclock
两个选项
-s, --hctosys set the system time from the RTC
-w, --systohc set the RTC from the system time
hwclock -s:将系统时间设置为RTC中的时间
hwclock -w:将RTC的时间设置为系统的时间
2、字符串转换为时间QDateTime
从指定格式的字符串中读取时间保存到类 QDateTime 中
QDateTime::fromString(time, "yyyy-MM-dd hh:mm:ss");
将 QDateTime 类中的时间,转换成字符串
QDateTime::toString("yyyy-MM-dd hh:mm:ss")
其中字符串的格式可以指定
1)日期格式说明
d: 日期为数字,不带零(1到31