This is a creation in Article, where the information may have evolved or changed.
In the go language, get the timestamp with time. Now (). Unix (), formatted time with T. Format, time for parsing. Parse.
Look at the instance code:
Package main Import ("FMT"" Time") Func main () {//Get time stampTimestamp:=Time . Now (). Unix () fmt. PRINTLN (timestamp)//formatted as a string, TM is of type timeTM:= 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 a string to a timestamp , the first argument is the format, the second is the time string to converttm2, _:= time. Parse ("01/02/2006","02/08/2015") fmt. Println (TM2. Unix ())}
Output Result:
1423361979
2015-02-08 10:19:39 AM
08/02/2015 10:19:39 AM
1423353600
Looking at the code above, you might wonder why the format string was used in the 2006-01-02 format. In the go language, these numbers are special letters, not random numbers, see the following list:
Month 1,01,jan,january
Day 2,02,_2
When 3,03,15,pm,pm,am,am
Sub 4,04
SEC 5,05
Year 06,2006
Weeks Mon,monday
Time zone difference means -07,-0700,z0700,z07:00,-07:00,mst
Time zone letter abbreviation MST