Linux同步网络时间
1.date '+%Y%M%D' 按照格式显示当前日期,结果如下:
[root@LAMP ~]# date "+%Y-%m-%d %H:%M:%S" 2016-08-16 20:01:25
2.date -s "xxx xx:xx:xx" 设置系统时间
[root@LAMP ~]# date -s "20160819 15:30:30" Fri Aug 19 15:30:30 HKT 2016
3.时间同步服务器
[root@LAMP ~]# ntpdate -u ntp.api.bz 29 Apr 15:26:27 ntpdate[2667]: step time server 61.153.197.226 offset -311.570389 sec
ntp常用服务器:
中国国家授时中心:210.72.145.44
NTP服务器(上海) :ntp.api.bz
美国: time.nist.gov
复旦: ntp.fudan.edu.cn
微软公司授时主机(美国) :time.windows.com
北京邮电大学 : s1a.time.edu.cn
清华大学 : s1b.time.edu.cn
北京大学 : s1c.time.edu.cn
台警大授时中心(台湾):asia.pool.ntp.org
4.时区操作
查看时区
1.date "+%Z"
[root@LAMP ~]# date "+%Z" HKT
2.使用cat /etc/sysconfig/clock查看当前时区
[root@LAMP ~]# cat /etc/sysconfig/clock ZONE="Asia/Hong_Kong"
设置时区
[root@LAMP ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime cp: overwrite `/etc/localtime'? y [root@LAMP ~]# date "+%Z" CST
5.将系统时间写入硬件
查看硬件时间
hwclock
同步系统时间
clock -w
[root@LAMP ~]# hwclock Tue 16 Aug 2016 08:09:24 PM CST -0.456264 seconds [root@LAMP ~]# hwclock -w [root@LAMP ~]# hwclock Fri 19 Aug 2016 12:24:08 AM CST -0.986792 seconds
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了