首页 最新 热门 推荐

  • 首页
  • 最新
  • 热门
  • 推荐

易记笔记-Ubuntu系统时间更改

  • 24-03-10 10:00
  • 3457
  • 10998
blog.csdn.net

常常不用,用的时候又忘记,所以专门记录修改系统时间的方法。

一、查看Ubuntu时间的方法

显示当前日期和时间:

 date -R
  • 1

或者

date
  • 1

设置日期和时间(需要超级用户权限):

sudo date MMDDhhmmYYYY
  • 1

注意这里的时间格式是月日时分年:

MM:月份
DD:日期
hh:小时(24小时制)
mm:分钟
YY:年份

例如,将时间设置为 2023 年 12 月 6 日 14 点 30 分:

sudo date 120614302023
  • 1

二、修改Ubuntu系统时间时区

sudo tzselect
  • 1
Please identify a location so that time zone rules can be set correctly.
Please select a continent, ocean, "coord", or "TZ".
 1) Africa
 2) Americas
 3) Antarctica
 4) Asia
 5) Atlantic Ocean
 6) Australia
 7) Europe
 8) Indian Ocean
 9) Pacific Ocean
10) coord - I want to use geographical coordinates.
11) TZ - I want to specify the time zone using the Posix TZ format.
#? 4
Please select a country whose clocks agree with yours.
 1) Afghanistan           18) Iraq                  35) Pakistan
 2) Antarctica            19) Israel                36) Palestine
 3) Armenia               20) Japan                 37) Philippines
 4) Azerbaijan            21) Jordan                38) Qatar
 5) Bahrain               22) Kazakhstan            39) Russia
 6) Bangladesh            23) Korea (North)         40) Saudi Arabia
 7) Bhutan                24) Korea (South)         41) Singapore
 8) Brunei                25) Kuwait                42) Sri Lanka
 9) Cambodia              26) Kyrgyzstan            43) Syria
10) China                 27) Laos                  44) 
11) Cyprus                28) Lebanon               45) Tajikistan
12) East Timor            29) Macau                 46) Thailand
13) Georgia               30) Malaysia              47) Turkmenistan
14)                       31) Mongolia              48) United Arab Emirates
15) India                 32) Myanmar (Burma)       49) Uzbekistan
16) Indonesia             33) Nepal                 50) Vietnam
17) Iran                  34) Oman                  51) Yemen
#? 10
Please select one of the following time zone regions.
1) Beijing Time
2) Xinjiang Time
#? 1

The following information has been given:

        China
        Beijing Time

Therefore TZ='Asia/Shanghai' will be used.
Selected time is now:   Wed Dec  7 17:27:16 CST 2022.
Universal Time is now:  Wed Dec  7 09:27:16 UTC 2022.
Is the above information OK?
1) Yes
2) No
#? 1

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58

以上为选择Asia\China\Shanghai 时间。

三、执行命令

sudo cp /usr/share/zoneinfo/Asia/Chongqing /etc/localtime
  • 1

替换以前的配置文件。

四、执行

sudo hwclock --systohc
  • 1

将时间写入cmos硬件时钟。

五、ntpdate 命令:用于手动同步时间与NTP服务器。

sudo ntpdate NTP SERVER
  • 1

启用/禁用网络时间同步(NTP):

sudo timedatectl set-ntp true   # 启用NTP
sudo timedatectl set-ntp false  # 禁用NTP
  • 1
  • 2

六、最后验证测试

sudo date -R
  • 1

查看系统时间是否更新为正确时间。这里需要注意“R”为大写。

除了使用命令行还可以通过图形界面修改,因为比较简单,就不做分享了。注意更改系统时间都需要管理员权限(sudo)。

Ubuntu(以及其他类UNIX系统)的时间工作原理

  • 硬件时钟(Real Time Clock - RTC): 计算机上有一个硬件时钟,RTC,它通常是一个独立的计时器芯片,负责在系统关闭时继续跟踪时间。这个硬件时钟通常设置为协调世界时(UTC)。

  • 操作系统时间: 当你启动计算机并加载Ubuntu时,操作系统会将硬件时钟的时间读取到系统内部来跟踪时间。Ubuntu默认情况下将这个时间转换为本地时区的时间。

  • 系统时间同步: Ubuntu系统通过网络与时间服务器同步时间。这确保了系统时间的准确性,可以通过 NTP(Network Time Protocol)来实现。

  • 时间管理和调整: Ubuntu操作系统有内置的时间管理机制,能够校正时间漂移和时钟偏差。这包括周期性地与时间服务器同步以及校准系统时钟。

随着系统版本的不同,可能还有其他命令和配置文件用于管理时间。无论你选择哪个命令,确保你有足够的权限来修改系统时间,并小心操作,以避免对系统产生不良影响。

推荐阅读

  • Ubuntu 20.04安装SQL Server
  • Ubuntu安装DHCP 服务和排错教程
  • Ubuntu 多路径服务报错处理方法
  • Ubuntu Samba高危安全漏洞修复
  • Ubuntu 用bind9搭建DNS服务器
  • Ubuntu18.04重启后网络不通处理方法
注:本文转载自blog.csdn.net的Par@ish的文章"https://blog.csdn.net/weixin_37813152/article/details/128224046"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接
复制链接
相关推荐
发表评论
登录后才能发表评论和回复 注册

/ 登录

评论记录:

未查询到任何数据!
回复评论:

分类栏目

后端 (14832) 前端 (14280) 移动开发 (3760) 编程语言 (3851) Java (3904) Python (3298) 人工智能 (10119) AIGC (2810) 大数据 (3499) 数据库 (3945) 数据结构与算法 (3757) 音视频 (2669) 云原生 (3145) 云平台 (2965) 前沿技术 (2993) 开源 (2160) 小程序 (2860) 运维 (2533) 服务器 (2698) 操作系统 (2325) 硬件开发 (2492) 嵌入式 (2955) 微软技术 (2769) 软件工程 (2056) 测试 (2865) 网络空间安全 (2948) 网络与通信 (2797) 用户体验设计 (2592) 学习和成长 (2593) 搜索 (2744) 开发工具 (7108) 游戏 (2829) HarmonyOS (2935) 区块链 (2782) 数学 (3112) 3C硬件 (2759) 资讯 (2909) Android (4709) iOS (1850) 代码人生 (3043) 阅读 (2841)

热门文章

101
推荐
关于我们 隐私政策 免责声明 联系我们
Copyright © 2020-2025 蚁人论坛 (iYenn.com) All Rights Reserved.
Scroll to Top