时间接口文档
//接口时间变化
- root@pc123:/# timedatectl
- Local time: Wed 2020-12-16 18:33:37 UTC
- Universal time: Wed 2020-12-16 18:33:37 UTC
- RTC time: Thu 1970-01-01 01:08:42
- Time zone: UTC (UTC, +0000)
- System clock synchronized: no
- NTP service: active
- RTC in local TZ: no
需要注意图中虚线的部分表示这个时间受到时区的影响!!!,
即localtime,mktime,strftime函数受到环境变量TZ的影响
而时区可通过tzset和设置环境变量去影响localtime
- 工具timedatectl 即可查看系统时间和时区
root@pc123:/usrdata# timedatectl Local time: Wed 2020-12-16 18:54:43 UTC Universal time: Wed 2020-12-16 18:54:43 UTC RTC time: Thu 1970-01-01 01:29:55 Time zone: UTC (UTC, +0000) System clock synchronized: no NTP service: active RTC in local TZ: no
- timedatectl list-timezones //查看当前支持的时区
- hwclock -w 保存到rtc时间
- 时区如何设置?
gettimeofday和settimeofday可读取/设置时间,时区。
clock_gettime:系统调用到调用do_clock_gettime
--->ktime_get_real_ts64
---->一步步跟进去发现是调用timekeep的 nsecs = timekeeping_get_ns(&tk->tkr_mono);
int do_clock_gettime(clockid_t which_clock, struct timespec64 *tp) { switch (which_clock) { case CLOCK_REALTIME: ktime_get_real_ts64(tp); break; case CLOCK_MONOTONIC: ktime_get_ts64(tp); break; case CLOCK_BOOTTIME: get_monotonic_boottime64(tp); break; default: return -EINVAL; } return 0; }