先记录一下我为什么要关注我设备的时区和时间显示方法;
我原本想在我的服务器上做几个定时的监控任务(crontab 任务),但是在我测试我任务的时候总是不能按照系统时间进行执行(我通过date来看是02:30:45)我就把任务执行的时间写在他的下一分钟结果没有执行(其实如果不改显示格式通过data -R看时间也可以)。
# 演示环境danny@danny-server:~$ cat /etc/issueUbuntu 22.04.1 LTS \n \l# data -R默认是24小时制显示danny@danny-server:~$ date -RSun, 29 Jan 2023 14:07:25 +0000# 通过date 我这里显示的是12小时制的时间,当时我就认为我的机器是凌晨两点多了danny@danny-server:~$ dateSun Jan 29 02:08:01 PM UTC 2023danny@danny-server:~$ timedatectl Local time: Sun 2023-01-29 14:10:47 UTC Universal time: Sun 2023-01-29 14:10:47 UTC RTC time: Sun 2023-01-29 14:10:47 Time zone: Etc/UTC (UTC, +0000)System clock synchronized: yes NTP service: active RTC in local TZ: no# 设置时区danny@danny-server:~$ timedatectl set-timezone Asia/Shanghai==== AUTHENTICATING FOR org.freedesktop.timedate1.set-timezone ===Authentication is required to set the system timezone.Multiple identities can be used for authentication: 1. ubuntu (admin-user) 2. Danny Niu,,, (danny)Choose identity to authenticate as (1-2): 2Password:==== AUTHENTICATION COMPLETE ===# 设置bios防止重启失效danny@danny-server:~$ sudo hwclock --systohc# 把时间格式调整为24小时制(需要先sudo bash进入root账户,修改/etc/default/locale)danny@danny-server:~/cronTask/dailyBuild$ cat /etc/default/localeLANG=en_US.UTF-8LC_TIME=en_DK.UTF-8# 效果展示danny@danny-server:~$ date -RSun, 29 Jan 2023 22:12:45 +0800danny@danny-server:~$ dateSun Jan 29 10:16:09 PM CST 2023danny@danny-server:~$ date -RSun, 29 Jan 2023 22:16:48 +0800#----------reboot---------------Last login: Sun Jan 29 22:07:19 2023 from 115.171.170.214danny@danny-server:~$ dateSun Jan 29 22:30:33 CST 2023danny@danny-server:~$
来源地址:https://blog.csdn.net/qq_36481693/article/details/128794954