docs: time zone

时区
This commit is contained in:
Shikong 2021-10-05 17:58:53 +08:00
parent 2dff96f6c2
commit fee0adc3da
2 changed files with 27 additions and 0 deletions

View File

@ -56,6 +56,8 @@ func main() {
t++
}
fmt.Println("=========================================================")
// 时间格式化
// Golang 中 时间格式化不是 常见的 yyyy-MM-DD HH:mm:ss
// 而是 2006-01-02 15:04:05 的形式

25
base/time/zone/main.go Normal file
View File

@ -0,0 +1,25 @@
package main
import (
"fmt"
"time"
)
func f1() {
now := time.Now()
fmt.Println(now)
loc, err := time.LoadLocation("Asia/Shanghai")
if err != nil {
fmt.Printf("Load Location Failed, err => %s", err)
return
}
fmt.Println("时区:", loc)
str, _ := time.ParseInLocation("2006-01-02 15:04:05.999", now.Add(24*time.Hour).Format("2006-01-02 15:04:05.999"), loc)
fmt.Println(str)
}
func main() {
f1()
}