29

Time

 6 years ago
source link: https://studygolang.com/articles/15301?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Time包

time包是用于统计当前系统时间的,time.Time类型,用来表示时间,获取当前时间, now := time.Now(),time.Now().Day(),time.Now().Minute(),time.Now().Month(),time.Now().Year()

fmt.Printf("%02d%02d%02d %02d:%02d:%02d\n", time.Now().Year(),
		time.Now().Month(),
		time.Now().Day(),
		time.Now().Hour(),
		time.Now().Minute(),
		time.Now().Second())

还有一种比较“恶心”的格式化做法:

利用Format()函数:

fmt.Println(time.Now().Format("2006/1/02 15:04:05"))

特别注意的地方是Format里面的参数必须是 2006/1/02 15:04:05 这个时间,当然格式也可以写成2006年01月02日 15:04:05

time包中还有一个比较常用的函数:Sleep()


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK