panic: time: missing Location in call to Time.In

  Back end, golang, time


1. docker empty image (or similar environment)

2. Used in Go applicationsloc, _ := time.LoadLocation("Asia/Chongqing")


$ go run ./xxx

panic: time:missing Location in call to Time.In


The location information of time is extracted from the local file system. Most systems support it, but it still depends on the current system. Specific configuration storage path:

$ cd /usr/share/zoneinfo

Enter the directory to see the configuration information of each time zone.

$ ls
+VERSION    Australia   EET         Factory     Greenwich   Jamaica     Mexico      Poland      US          posixrules
Africa      Brazil      EST         GB          HST         Japan       NZ          Portugal    UTC
America     CET         EST5EDT     GB-Eire     Hongkong    Kwajalein   NZ-CHAT     ROC         Universal
Antarctica  CST6CDT     Egypt       GMT         Iceland     Libya       Navajo      ROK         W-SU
Arctic      Canada      Eire        GMT+0       Indian      MET         PRC         Singapore   WET
Asia        Chile       Etc         GMT-0       Iran        MST         PST8PDT     Turkey      Zulu
Atlantic    Cuba        Europe      GMT0        Israel      MST7MDT     Pacific     UCT

However, these time zone configuration files do not exist in empty images (or similar scenes), and this error will appear when the program refers to them.

(To be precise, this problem arises because the local system does not exist.)Asia/ChongqingTime zone profile for)



$ apk add --no-cache tzdata

After installing this package, the/usr/share/zoneinfoDirectory to generate configuration information for each time zone

Note that if there is no configuration for timezone and locatime, it needs to be handled manually.


Do you know what tzdata is? Simply put, it is a time zone database (as files and modules)

The purpose of this software package is to distribute the standard time zone database in the cabal software package so that it can be used uniformly for Haskell programs on all platforms.