标签:个数 sprintf div ++ orm day lis == format
package main import ( "fmt" "time" ) func main() { //看看日期和时间相关函数和方法使用 //1. 获取当前时间 now := time.Now() fmt.Printf("now=%v now type=%T\n", now, now) //now=2020-01-20 03:43:53.1244468 +0800 CST m=+0.002990201 now type=time.Time //2.通过now可以获取到年月日,时分秒 fmt.Printf("年=%v\n", now.Year()) //年=2020 fmt.Printf("月=%v\n", now.Month()) //月=January fmt.Printf("月=%v\n", int(now.Month())) //月=1 fmt.Printf("日=%v\n", now.Day()) //日=20 fmt.Printf("分=%v\n", now.Minute()) //分=43 fmt.Printf("秒=%v\n", now.Second()) //秒=53 //格式化日期时间 fmt.Printf("当前年月日 %d-%d-%d %d:%d:%d \n", now.Year(), //当前年月日 2020-1-20 3:45:48 now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second()) dateStr := fmt.Sprintf("当前年月日 %d-%d-%d %d:%d:%d \n", now.Year(), //dateStr=当前年月日 2020-1-20 3:45:48 now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second()) fmt.Printf("dateStr=%v\n", dateStr) //格式化日期时间的第二种方式 fmt.Printf(now.Format("2006-01-02 15:04:05")) //2020-01-20 03:45:48 fmt.Println() fmt.Printf(now.Format("2006-01-02")) //2020-01-20 fmt.Println() fmt.Printf(now.Format("15:04:05")) //03:45:48 fmt.Println() fmt.Printf(now.Format("2006")) //2020 fmt.Println() //需求,每隔1秒中打印一个数字,打印到100时就退出 //需求2: 每隔0.1秒中打印一个数字,打印到100时就退出 // i := 0 // for { // i++ // fmt.Println(i) // //休眠 // //time.Sleep(time.Second) // time.Sleep(time.Millisecond * 100) // if i == 100 { // break // } // } //Unix和UnixNano的使用 fmt.Printf("unix时间戳=%v unixnano时间戳=%v\n", now.Unix(), now.UnixNano()) //unix时间戳=1579463148 unixnano时间戳=1579463148802059600 }
标签:个数 sprintf div ++ orm day lis == format
原文地址:https://www.cnblogs.com/yzg-14/p/12216382.html