time日期包
package main
import (
"fmt"
"time"
)
func main() {
timeNow := time.Now()
fmt.Println(timeNow)
fmt.Println(timeNow.Year())
fmt.Println(timeNow.Month())
fmt.Println(timeNow.Day())
fmt.Println(timeNow.Hour())
fmt.Println(timeNow.Minute())
fmt.Println(timeNow.Second())
timeStr := timeNow.Format("2006年-01月-02日 15:04:05")
fmt.Println(timeStr)
timeUnix := timeNow.Unix()
fmt.Println(timeUnix)
timeNow1 := time.Unix(timeUnix, 0)
fmt.Println(timeNow1)
str := "2020-10-14 22:06"
tmp := "2006-01-02 15:04"
timeNow2, _ := time.ParseInLocation(tmp, str, time.Local)
fmt.Println(timeNow2)
ticker := time.NewTicker(time.Second)
n := 5
for v := range ticker.C {
n--
if n == 0 {
ticker.Stop()
break
}
fmt.Println(v)
}
fmt.Println("第一次")
time.Sleep(time.Second)
fmt.Println("第二次")
time.Sleep(time.Second)
fmt.Println("第三次")
time.Sleep(time.Second)
fmt.Println("第四次")
time.Sleep(time.Second)
fmt.Println("第五次")
}