Created
November 2, 2018 07:36
-
-
Save yedamao/96dbd6bbd35ef59f428225c5557eb6f7 to your computer and use it in GitHub Desktop.
golang time pkg handle DST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func main() { | |
losAngeles, err := time.LoadLocation("America/Los_Angeles") | |
if err != nil { | |
panic(err) | |
} | |
// 夏令时开始 | |
// 洛杉矶在当地时间 2018年03月11日,02:00:00 时钟向前调整 1 小时 变为 2018年03月11日,03:00:00,开始夏令时 | |
layout := "2006-01-02 15:04:05" | |
time1, err := time.ParseInLocation(layout, "2018-03-11 01:59:59", losAngeles) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println(time1) // 2018-03-11 01:59:59 -0800 PST | |
fmt.Println(time1.Add(time.Second)) // 2018-03-11 03:00:00 -0700 PDT | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment