Joe*_*eng 4 time timezone-offset google-colaboratory
问题:为什么 Colab 的时区与本地时区不同?
背景::我住在美国。但Colab时间(我指定的是美国时区)与当地时间有五个小时的时差。
代码:
!rm /etc/localtime
!ln -s /usr/share/zoneinfo/US /etc/localtime # the time should be around 11:20
!date
Run Code Online (Sandbox Code Playgroud)
结果: 2019 年 8 月 7 日星期三 16:20:40 世界标准时间
您可以通过两步更改时区:
第 1 步:在层次结构中查找您所在时区的名称
!ls -al /usr/share/zoneinfo/
Run Code Online (Sandbox Code Playgroud)
对于美国,您可以通过以下方式遍历时区树一层:
!ls -al /usr/share/zoneinfo/US
Run Code Online (Sandbox Code Playgroud)
这给了你
drwxr-xr-x 2 root root 4096 Dec 22 02:14 .
drwxr-xr-x 21 root root 4096 Dec 22 02:14 ..
lrwxrwxrwx 1 root root 20 Oct 23 06:18 Alaska -> ../America/Anchorage
lrwxrwxrwx 1 root root 15 Oct 23 06:18 Aleutian -> ../America/Adak
lrwxrwxrwx 1 root root 18 Oct 23 06:18 Arizona -> ../America/Phoenix
lrwxrwxrwx 1 root root 18 Oct 23 06:18 Central -> ../America/Chicago
lrwxrwxrwx 1 root root 13 Oct 23 06:18 Eastern -> ../posixrules
lrwxrwxrwx 1 root root 21 Oct 23 06:18 East-Indiana -> ../America/Fort_Wayne
lrwxrwxrwx 1 root root 19 Oct 23 06:18 Hawaii -> ../Pacific/Honolulu
lrwxrwxrwx 1 root root 18 Oct 23 06:18 Indiana-Starke -> ../America/Knox_IN
lrwxrwxrwx 1 root root 18 Oct 23 06:18 Michigan -> ../America/Detroit
lrwxrwxrwx 1 root root 9 Oct 23 06:18 Mountain -> ../Navajo
lrwxrwxrwx 1 root root 22 Oct 23 06:18 Pacific -> ../America/Los_Angeles
lrwxrwxrwx 1 root root 17 Oct 23 06:18 Samoa -> ../Pacific/Midway
Run Code Online (Sandbox Code Playgroud)
第2步:
使用步骤 1 中获得的正确参考设置时区。如果您居住在芝加哥,则正确的参考将是:Central。您可以通过以下方式更改 Google Colabo 时区:
!rm /etc/localtime
!ln -s /usr/share/zoneinfo/US/Central /etc/localtime
!date
Run Code Online (Sandbox Code Playgroud)
请记住,正确的引用位于两级层次结构中,首先包含区域 ( US/Central),而不仅仅是时区Central。