This is a creation in Article, where the information may have evolved or changed.
Constant declaration:
Const Timelayout " 2006-01-02 15:04:05 "
This is a wonderful, must be this time point, is said to be the day of the birth of Go, memory method: 6-1-2-3-4-5
1. Get the current timestamp
func Getcurrentsystemtimestamp () Int64 { return time . Now (). Unix ()}
2. Get the current string time
string { return time . Now (). Format (timelayout)}
3. Timestamp to String time format
Func timestamp2standardtimestr (timestampstring { returntime . Unix (timestamp0). Format (timelayout)}
4. String time-to-timestamp
This is a little bit more complicated, in the Golang language, when this time conversion is done, if you are using parse to format directly, the default is to use UTC format. So what exactly is the UTC time format?
The entire Earth is divided into 24 time zones, each with its own local time. In international radiocommunication situations, for the sake of unification, a uniform time is used, known as universal Coordination (UTC, Universal-time coordinated). UTC, like Greenwich mean Time (GMT, Greenwich Mean time), is the same as in London, England. Beijing time Zone is the East Eight District, leading UTC eight hours, so if the incoming string is: 2017-11-13 11:14:21, the result will return UTC after the conversion timestamp is: 1510571661 (2017-11-13 19:14:21).
To solve this problem, you need to use the other parsing function that time gives us: parseinlocaltion
Func Timestr2timestamp (timestrstring) Int64 {//get local time zoneLOC, _: = time. Loadlocation ("Local") //the time string at the end of the read file will be preceded by a newline character, which needs to be removed or resolved.TM, Error: = time. Parseinlocation (Timelayout, strings. Trim (TIMESTR,"\ n"), loc)ifError! =Nil {log. Fatal (Error)return 0 } returnTM. Unix ()}