Zan*_*ynx 14
查看rtc手册页了解详细信息,但如果您以root身份登录,则执行以下操作:
#include <linux/rtc.h>
#include <sys/ioctl.h>
struct rtc_time {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday; /* unused */
int tm_yday; /* unused */
int tm_isdst;/* unused */
};
int fd;
struct rtc_time rt;
/* set your values here */
fd = open("/dev/rtc", O_RDONLY);
ioctl(fd, RTC_SET_TIME, &rt);
close(fd);
Run Code Online (Sandbox Code Playgroud)
在调用stime()之后,执行以下操作:
system("/sbin/hwclock --systohc");
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请参见hwclock(8)手册页.