18.04 未显示正确时间(不是双重启动问题)

18.04 未显示正确时间(不是双重启动问题)

我意识到这是一个常见问题,但我找不到解决问题的方法。

居住在“美国/芝加哥(CST,-0600)”,但 ubuntu 显示的是 UTC 时间。

当地时间下午 4 点:

$ timedatectl  
                      Local time: Thu 2018-11-22 16:11:47 CST  
                  Universal time: Thu 2018-11-22 22:11:47 UTC  
                        RTC time: Thu 2018-11-22 22:11:47  
                       Time zone: America/Chicago (CST, -0600)  
       System clock synchronized: yes  
 systemd-timesyncd.service active: yes  
                 RTC in local TZ: no  

因此 TimeDateCtl 知道当地时间,但 Date 命令显示为 UTC

$ date
Thu Nov 22 22:15:54 Chicago 2018

我已经确保BIOS时间是UTC,而且我的服务已启动,就是不对。

● systemd-timesyncd.service - Network Time Synchronization
   Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2018-11-22 22:07:07 Chicago; 9min ago
     Docs: man:systemd-timesyncd.service(8)
 Main PID: 1360 (systemd-timesyn)
   Status: "Synchronized to time server 91.189.89.199:123 (ntp.ubuntu.com)."
    Tasks: 2 (limit: 4915)
   CGroup: /system.slice/systemd-timesyncd.service
           └─1360 /lib/systemd/systemd-timesyncd

我还能尝试什么?我将其设置为本地时间并恢复,我重新启动了所有能找到的服务。

编辑,我这里也没有发现问题:

sudo hwclock——调试

hwclock from util-linux 2.31.1
System Time: 1542925579.769423
Trying to open: /dev/rtc0
Using the rtc interface to the clock.
Assuming hardware clock is kept in UTC time.
Waiting for clock tick...
...got clock tick
Time read from Hardware Clock: 2018/11/22 22:26:20
Hw clock time : 2018/11/22 22:26:20 = 1542925580 seconds since 1969
Time since last adjustment is 1542925580 seconds
Calculated Hardware Clock drift is 0.000000 seconds
2018-11-22 22:26:19.764979+0000

答案1

您的环境变量TZ是导致问题的原因。

$ echo $TZ
Chicago/New_York

Chicago/New_York是无效的时区,因此date将默认为 UTC,但由于某种原因,仍然将区域名称的第一部分显示为时区,导致:

$ timedatectl  
                      Local time: Thu 2018-11-22 16:11:47 CST  
                  Universal time: Thu 2018-11-22 22:11:47 UTC  
                        RTC time: Thu 2018-11-22 22:11:47  
                       Time zone: America/Chicago (CST, -0600)  
       System clock synchronized: yes  
 systemd-timesyncd.service active: yes  
                 RTC in local TZ: no  

$ date
Thu Nov 22 22:15:54 Chicago 2018

现在要修复该问题,我们只需要找出错误值设置的位置并删除该行。在您的 shell/配置文件初始化脚本中搜索以下行之一,例如~/.profile,或者如果它影响所有用户,~/.bashrc甚至可能/etc/environment/etc/profile或者:/etc/profile.d/*/etc/bash.bashrc

TZ='Chicago/New_York'
export TZ='Chicago/New_York'

相关内容