gf/geg/os/gtime/gtime_linkop.go
2018-07-22 11:58:38 +08:00

23 lines
558 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"fmt"
"gitee.com/johng/gf/g/os/gtime"
"time"
)
func main() {
// 去年今日
fmt.Println(gtime.Now().AddDate(-1, 0, 0).Format("Y-m-d"))
// 去年今日UTC时间
fmt.Println(gtime.Now().AddDate(-1, 0, 0).Format("Y-m-d H:i:s T"))
fmt.Println(gtime.Now().AddDate(-1, 0, 0).UTC().Format("Y-m-d H:i:s T"))
// 下个月1号凌晨0点整
fmt.Println(gtime.Now().AddDate(0, 1, 0).Format("Y-m-d 00:00:00"))
// 2个小时前
fmt.Println(gtime.Now().Add(-time.Hour).Format("Y-m-d H:i:s"))
}