Golang之时间格式化,计时器
地鼠敲下一堆代码,记录着当天的时间
package main import ( "fmt" "time" ) func getTime() { now := time.Now() timeStr := now.Format("2006/01/02 15:04:05") fmt.Printf("time:%s\n", timeStr) } func testFormat2() { now := time.Now() timeStr := fmt.Sprintf("%02d/%02d/%02d %02d:%02d:%02d\n", now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second()) fmt.Printf("time:%s\n", timeStr) } func testCost() { start := time.Now().UnixNano() for i := 0; i < 10; i++ { time.Sleep(time.Millisecond) } end := time.Now().UnixNano() cost := (end - start) / 1000 fmt.Printf("code cost:%d us\n", cost) } func main() { //getTime() //testFormat2() testCost() }
努力成为一个开发者
个人站点:www.pythonav.cn