go 中打印时间

package main

import (
	"fmt"
	"time"
)

func main() {
    //打印当前时间 ,格式“2006-01-02 15:04:05 Mon
    //“2006-01-02 15:04:05是go的诞生时间,所以这么设计Format的Layout”
    var goos = time.Now().Format("2006-01-02 15:04:05")
    fmt.Printf("the current time:%s \n", goos)
    fmt.Println(time.Now().Format("2006-01-02 15:04:05"))
    fmt.Println(time.Now().Format("2006-01-02 15:04:05 Mon"))

}

打印一个程序执行的时间

package main

import (
	"fmt"
	"time"
	"os"
)

func HostName(){
	os.Hostname()
}
func main(){
	new :=time.Now()
	fmt.Println(new.Format("2006-01-02 15:04:05"))
	
	start := time.Now().UnixNano()
	HostName()
	end := time.Now().UnixNano()

	fmt.Printf("cost is :%d \n", ( end-start)/1000)

}

猜你喜欢

转载自blog.csdn.net/u011327801/article/details/90038725
今日推荐