Panic:time:missing location on call to Time.in

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Premise

1. Docker image (or similar environment)

2, the Go application uses theloc, _ := time.LoadLocation("Asia/Chongqing")

Problem

$ go run ./xxxpanic: time:missing Location in call to Time.In

Reason

The location information for the time is extracted from the local file system, which is supported by most systems, but still depends on the current system. Specific Configuration Storage path:

$ cd /usr/share/zoneinfo

Enter the directory to see the configuration information for each time zone

$ ls+VERSION    Australia   EET         Factory     Greenwich   Jamaica     Mexico      Poland      US          posixrulesAfrica      Brazil      EST         GB          HST         Japan       NZ          Portugal    UTC         zone.tabAmerica     CET         EST5EDT     GB-Eire     Hongkong    Kwajalein   NZ-CHAT     ROC         UniversalAntarctica  CST6CDT     Egypt       GMT         Iceland     Libya       Navajo      ROK         W-SUArctic      Canada      Eire        GMT+0       Indian      MET         PRC         Singapore   WETAsia        Chile       Etc         GMT-0       Iran        MST         PST8PDT     Turkey      ZuluAtlantic    Cuba        Europe      GMT0        Israel      MST7MDT     Pacific     UCT         iso3166.tab

However, these time zone profiles do not exist in an empty image (or similar scenario), and this error occurs when the program is referenced.

(accurately, this problem occurs because the local system does not exist Asia/Chongqing for a time zone profile)

Solve

Installation

$ apk add --no-cache tzdata

After the package is installed, /usr/share/zoneinfo configuration information for each time zone is generated under the directory

Note that if you do not have a timezone, locatime configuration, you need to manually handle

At last

Do you know what Tzdata is? In short, it's a time zone database (as files and modules)

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.