mirror of
https://gitee.com/shikong-sk/golang-study
synced 2025-02-23 15:32:15 +08:00
docs: time zone
时区
This commit is contained in:
parent
2dff96f6c2
commit
fee0adc3da
@ -56,6 +56,8 @@ func main() {
|
|||||||
t++
|
t++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("=========================================================")
|
||||||
|
|
||||||
// 时间格式化
|
// 时间格式化
|
||||||
// Golang 中 时间格式化不是 常见的 yyyy-MM-DD HH:mm:ss
|
// Golang 中 时间格式化不是 常见的 yyyy-MM-DD HH:mm:ss
|
||||||
// 而是 2006-01-02 15:04:05 的形式
|
// 而是 2006-01-02 15:04:05 的形式
|
||||||
|
25
base/time/zone/main.go
Normal file
25
base/time/zone/main.go
Normal 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()
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user