LUKIYA'S NEVERLAND

春去秋来,花谢花开。

golang docker from scrach 设置时区(set timezone,1.15, time/tzdata)

12/05/2020 01:15:13 AM Views: 7 Pictures: 0

If you want to build docker image from scrach, there's no timezone data in it, you will need to copy timezone data from linux system.

如果你需要从scrach构建docker image,是没有时区数据的,这时需要从linux系统里复制

But in golang 1.15, there's a new pacakge "time/tzdata" which will embed timezone data into your program while building. There are two ways to do it:

但是从golang 1.15开始,引入了一个新的包"time/tzdata“,编译的时候可以将时区数据内嵌进去。实现起来有两种方式

1. add import _ "time/tzdata" in your main pakcage

在main包中添加 import _ "time/tzdata"

2. build with -tags timetzdata

编译时指定参数 -tags timetzdata

Then, you can set Local timezone:

然后就可以指定Local时区了:

var err error

time.Local, err = time.LoadLocation("America/Los_Angeles")