golang get current time, custom time format

1. Get the current time

package main

import "time"

now_time := time.Now()
fmt.Println(now_time)

Print result:

2020-08-19 10:36:49.738716241 +0800 CST m=+0.000126403

2. Get the current time in a custom format

package main

import "time"

now_time := time.Now()
fmt.Println(now_time)

currentTime := now_time.Format("20060102")
fmt.Print(currentTime)

Print result:

20200819

Note : When setting the time format, the time in the time format must be 2006-01-02 15:04:05. This is a weird thing, it must be this point in time, it is said to be the birth date of go, the memory method: 6-1- 2-3-4-5

Guess you like

Origin blog.csdn.net/weixin_43202081/article/details/108095080