struct timespec ts;
ts = current_kernel_time();
printk(KERN_ALERT "i=%d, channel=%d, %ld %ld\n", i, channel, ts.tv_sec, ts.tv_nsec);
struct timeval tv;
/*获取时间*/
do_gettimeofday(&tv);
printk(KERN_ALERT "now: %ld %ld\n", tv.tv_sec, tv.tv_usec);
/*设置时间, 时钟调后5小时*/
ts.tv_sec = tv.tv_sec + 3600*5;
do_settimeofday(&ts);
结果:
i=0, channel=0, 1523614738 199999523
now: 1523614738 207424
头文件在linux/timekeeping32.h中。要根据自己的需要进行选择和转换。

595

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



