Skip to content

Instantly share code, notes, and snippets.

@yedamao
Created November 2, 2018 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yedamao/96dbd6bbd35ef59f428225c5557eb6f7 to your computer and use it in GitHub Desktop.
Save yedamao/96dbd6bbd35ef59f428225c5557eb6f7 to your computer and use it in GitHub Desktop.
golang time pkg handle DST
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