mirror of
https://gitee.com/johng/gf
synced 2026-06-27 09:47:19 +08:00
完善gtime示例程序
This commit is contained in:
@ -9,15 +9,11 @@ func main() {
|
||||
formats := []string{
|
||||
"Y-m-d H:i:s.u",
|
||||
"D M d H:i:s T O Y",
|
||||
// 可以使用转义字符转移有意义的格式字母
|
||||
"\\T\\i\\m\\e \\i\\s: h:i:s a",
|
||||
// format格式不支持标准库格式混合,相互隔离
|
||||
"2006-01-02T15:04:05.000000000Z07:00",
|
||||
}
|
||||
t := gtime.Now()
|
||||
for _, f := range formats {
|
||||
fmt.Println(f)
|
||||
fmt.Println(t.Format(f))
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
|
||||
15
geg/os/gtime/gtime_func.go
Normal file
15
geg/os/gtime/gtime_func.go
Normal file
@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gitee.com/johng/gf/g/os/gtime"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("Date :", gtime.Date())
|
||||
fmt.Println("Datetime :", gtime.Datetime())
|
||||
fmt.Println("Second :", gtime.Second())
|
||||
fmt.Println("Millisecond:", gtime.Millisecond())
|
||||
fmt.Println("Microsecond:", gtime.Microsecond())
|
||||
fmt.Println("Nanosecond :", gtime.Nanosecond())
|
||||
}
|
||||
@ -14,8 +14,6 @@ func main() {
|
||||
}
|
||||
t := gtime.Now()
|
||||
for _, f := range formats {
|
||||
fmt.Println(f)
|
||||
fmt.Println(t.Layout(f))
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
|
||||
22
geg/os/gtime/gtime_linkop.go
Normal file
22
geg/os/gtime/gtime_linkop.go
Normal file
@ -0,0 +1,22 @@
|
||||
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"))
|
||||
}
|
||||
Reference in New Issue
Block a user