Google Colab 的不同时区
Different timezone in Google Colab
问题:为什么 Colab 的时区与本地时区不同?
背景::我住在美国。但是 Colab 时间(我指定的是美国时区)和当地时间有五个小时的时差。
代码:
!rm /etc/localtime
!ln -s /usr/share/zoneinfo/US /etc/localtime # the time should be around 11:20
!date
结果:
8 月 7 日星期三 16:20:40 UTC 2019
Google Colab 服务器的默认时区是 UTC 时间。这是英国伦敦的时间。你需要用代码把UTC时间转换成其他时区比如东部时间(纽约)。
您可以分两步更改时区:
第一步:
在层次结构中查找您的时区名称
!ls -al /usr/share/zoneinfo/
对于美国,您将通过以下方式再遍历时区树一级:
!ls -al /usr/share/zoneinfo/US
这给了你
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
第 2 步:
使用步骤 1 中获得的正确参考设置时区。
如果你住在在芝加哥,正确的引用是:Central
。
您可以通过以下方式更改 Google Colabo 时区:
!rm /etc/localtime
!ln -s /usr/share/zoneinfo/US/Central /etc/localtime
!date
请记住,正确的引用是在两级层次结构中首先包含地区 (US/Central
),而不仅仅是时区 Central
。
问题:为什么 Colab 的时区与本地时区不同?
背景::我住在美国。但是 Colab 时间(我指定的是美国时区)和当地时间有五个小时的时差。
代码:
!rm /etc/localtime
!ln -s /usr/share/zoneinfo/US /etc/localtime # the time should be around 11:20
!date
结果: 8 月 7 日星期三 16:20:40 UTC 2019
Google Colab 服务器的默认时区是 UTC 时间。这是英国伦敦的时间。你需要用代码把UTC时间转换成其他时区比如东部时间(纽约)。
您可以分两步更改时区:
第一步: 在层次结构中查找您的时区名称
!ls -al /usr/share/zoneinfo/
对于美国,您将通过以下方式再遍历时区树一级:
!ls -al /usr/share/zoneinfo/US
这给了你
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
第 2 步:
使用步骤 1 中获得的正确参考设置时区。
如果你住在在芝加哥,正确的引用是:Central
。
您可以通过以下方式更改 Google Colabo 时区:
!rm /etc/localtime
!ln -s /usr/share/zoneinfo/US/Central /etc/localtime
!date
请记住,正确的引用是在两级层次结构中首先包含地区 (US/Central
),而不仅仅是时区 Central
。