This is a creation in Article, where the information may have evolved or changed.
Get local time
// get current timestamp currentTime := time.Now().Local() //print time fmt.Println(currentTime)
Specifies the format of the date character type
// get current timestamp currentTime := time.Now().Local()//format Time, string type newFormat := currentTime.Format("2006-01-02 15:04:05.000") fmt.Println(newFormat)
Constructs a specified time type
2016-02-1723:59:59.999, DateTime type myTime := time.Date(0162, time.February17235959999, time.UTC) //output the myTime fmt.Println("MyTime:", myTime.Format("2006-01-02 15:04:05.000"))
Full code:
Package Mainimport ("FMT" "Time") func Formattime () {//Get current timestamp currenttime: = time. now(). Local()//print Time FMT. Println(currenttime)//format time, String type Newformat: = CurrentTime. Format("2006-01-02 15:04:05.000") FMT. Println(Newformat)//build time .- Geneva- - at: -:59.999, DateTime type myTime: = time. Date(0162, Time. February, -, at, -, -,999, Time. UTC)//output the MyTime FMT. Println("MyTime:", MyTime. Format("2006-01-02 15:04:05.000"))//current milliseconds FMT. Println("milliseconds:", Time. now(). Unixnano()/int64 (time. Millisecond))//todo changing time layout (form)}func main () {Formattime ()}
Welcome to my public number.