4

Question: Why is the timezone in Colab different from local timezone?

Background:: I'm living in US. But 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

Joey Fueng
  • 95
  • 2
  • 7

2 Answers2

5

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.

Agile Bean
  • 6,437
  • 1
  • 45
  • 53
1

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.

Farzad Amirjavid
  • 649
  • 5
  • 13
  • UTC time is not the same as "_the time in London, UK_". Consider the difference between Greenwich Mean Time ([GMT](https://en.wikipedia.org/wiki/Greenwich_Mean_Time)) and British Summer Time ([BST](https://en.wikipedia.org/wiki/British_Summer_Time)). So, for much of the year UTC is one hour different from "_the time in London, UK_", based on what a wall clock will show you. – andrewJames Jul 11 '22 at 01:17