问题
Question: Why does the timezone in Colab different from local timezone?
Background:: I'm living in US. But the there is a five hours difference between the Colab time (I specify the US timezone) and local time.
Code:
!rm /etc/localtime
!ln -s /usr/share/zoneinfo/US /etc/localtime # the time should be around 11:20
!date
Results: Wed Aug 7 16:20:40 UTC 2019
回答1:
You can change the timezone in two steps:
Step 1: Find the name of your timezone in the hierarchy
!ls -al /usr/share/zoneinfo/
For US, you would then traverse the timezone tree one more level by:
!ls -al /usr/share/zoneinfo/US
which gives you
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
Step 2:
Set the time zone with the correct reference obtained in Step 1.
If you lived e.g. in Chicago, the correct reference would be: Central
.
You can change the Google Colabo timezone by:
!rm /etc/localtime
!ln -s /usr/share/zoneinfo/US/Central /etc/localtime
!date
Remember the correct reference is in a hierarchy of two levels containing the region first (US/Central
), not just the time zone Central
.
回答2:
The default time zone with Google Colab servers is UTC time. This is the time in London, UK. You need to convert the UTC time to other time zones such as eastern time (New York) with code.
来源:https://stackoverflow.com/questions/57398787/different-timezone-in-google-colab