Go语言time包
程序员文章站
2022-03-25 09:52:31
...
func main(){
/*预定义的时间格式*/
t1:=time.Now().Format(time.RFC3339)
fmt.Println("t1:",t1)
if t,err:=time.Parse(time.RFC3339,t1);err!=nil{
fmt.Println("parse:",err)
}else{
fmt.Println("t2:",t.String())//t.Format("2006-01-02 15:04:05.999999999 -0700 MST")
}
/*type Weekday int Sunday在time中是0,周一到周六分别是0~6*/
//t3:=time.Date(2018,10,1,1,1,1,1,time.Local)//t3: 2018-10-01 01:01:01.000000001 +0800 CST
t3:=time.Date(2018,10,1,1,1,1,1,time.UTC)//2018-10-01 01:01:01.000000001 +0000 UTC
fmt.Println("t3:",t3.String())
t4:=time.Now().Unix()
fmt.Println("t4:",time.Now().String())//t4: 2018-10-29 17:12:17.1068742 +0800 CST m=+0.048867701
t5:=time.Unix(t4,0)
fmt.Println("t5:",t5.String())//t5: 2018-10-29 17:12:17 +0800 CST
fmt.Println("t5+100s:",t5.Add(time.Second*100).String())//t5: 2018-10-29 17:12:17 +0800 CST
}
上一篇: vue-vueRouter路由拦截