前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >修改Linux系统时间,和网络时间同步

修改Linux系统时间,和网络时间同步

作者头像
JaneYork
发布2023-10-11 14:01:27
6750
发布2023-10-11 14:01:27
举报
文章被收录于专栏:PUSDN平行宇宙软件开发者网

1.手动修改(缺点:有偏差)

使用date查看当前时间

代码语言:javascript
复制
date -s 时分秒:修改时间  eg:date -s 8:10:10
date -s 完整时间YYYY-MM-DD hh:mm[:ss]  eg: "2018-10-10 10:10:10"
注意双引号

重启Linux,时间失效,可以将时间写入BIOS,

代码语言:javascript
复制
hwclock -w

2.使用网络时间,与网络时间同步

查看ntp服务是否启动

代码语言:javascript
复制
service --status-all      ###检查ntp服务是否启动
service ntpd status  ###如果没安装会提示,
代码语言:javascript
复制
如果没有安装ntp
安装ntp服务命令:
apt-get install ntp  或者 yum install ntp

查看当前时区:date -R

如果是-0500,则不正常,+0800为正常时区

2.1使用tzselect更改时区,选择亚洲 - 中国 - 北京,看英文

修改完成之后可以再次查看时区:date -R,如果还是-0500,请进行最后一步。

代码语言:javascript
复制
复制文件:
cp /usr/share/zoneinfo/Aisa/Shanghai /etc/localtime
可以使用Tab键快速提示

-- end --

附:

如果没有更改成功出现这种情况:

代码语言:javascript
复制
You can make this change permanent for yourself by appending the line
        TZ='Asia/Shanghai'; export TZ
to the file '.profile' in your home directory; then log out and log in again.

Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Asia/Shanghai
代码语言:javascript
复制
vi /etc/profile    #编辑文本
在 profile 文件中追加 TZ='Asia/Shanghai'; export TZ
source /etc/profile     #使用source命令使其生效


或者直接使用:
echo "TZ='Asia/Shanghai'; export TZ" >> /etc/profile; source /etc/profile
注意: >> 为 追加,> 是覆盖,此处用 >>
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-10-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档