【问题标题】:Different timezone in Google ColabGoogle Colab 中的不同时区
【发布时间】:2019-08-07 16:30:42
【问题描述】:

问题:为什么 Colab 中的时区与本地时区不同?

背景::我住在美国。但是 Colab 时间(我指定美国时区)和本地时间之间有五个小时的差异。

代码:

!rm /etc/localtime
!ln -s /usr/share/zoneinfo/US /etc/localtime # the time should be around 11:20
!date

结果: 2019 年 8 月 7 日星期三 16:20:40 UTC

【问题讨论】:

标签: time google-colaboratory timezone-offset


【解决方案1】:

您可以分两步更改时区:

第 1 步: 在层次结构中查找您的时区名称

!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

【讨论】:

    【解决方案2】:

    Google Colab 服务器的默认时区是 UTC 时间。这是英国伦敦的时间。您需要使用代码将 UTC 时间转换为其他时区,例如东部时间(纽约)。

    【讨论】:

      猜你喜欢
      • 2021-10-20
      • 2020-05-20
      • 1970-01-01
      • 2020-08-30
      • 2021-09-05
      • 2019-06-15
      • 1970-01-01
      • 2020-02-04
      • 2021-07-22
      相关资源
      最近更新 更多