This is a creation in Article, where the information may have evolved or changed.
Package <textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;">main Import ("FMT" "Time") Func main () {//get timestamp timestamp: = times. Now (). Unix () fmt. PRINTLN (timestamp)//formatted as a string, TM is Time type TM: = time. Unix (timestamp, 0) fmt. Println (TM. Format ("2006-01-02 03:04:05 PM")) fmt. Println (TM. Format ("02/01/2006 15:04:05 PM"))//convert from string to timestamp, the first argument is format, the second is the time string to be converted tm2, _: = times. Parse ("01/02/2006", "02/08/2015") fmt. Println (TM2. Unix ())}</textarea>
| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
Package Main Import ("FMT""Time") funcMain() {//Get timestamptimestamp := Time. Now().Unix()FMT.Println(timestamp) //format as String, TM as time typeTM := Time.Unix(timestamp, 0)FMT.Println(TM.Format("2006-01-02 03:04:05 PM"))FMT.Println(TM.Format("02/01/2006 15:04:05 PM")) //from string to timestamp, first argument is format, second is the time string to convertTM2, _ := Time.Parse("01/02/2006", "02/08/2015") FMT.Println(TM2.Unix())} |
go timestamp and date string conversion to each other