I want to convert UTC time string to unix timestamp. I do this
fmt.Printf("%s %d\n", time.Now().String(), time.Now().Unix()) fmt.Printf("%s %s\n", time.Now().UTC().String(), time.Now().UTC().Unix())
But I got same unix timestamp 1499018765
2017-07-02 20:06:05.5582802 +0200 CEST 1499018765
2017-07-02 18:06:05.791337 +0000 UTC 1499018765
Use the getTime() method to get a UTC timestamp, e.g. new Date(). getTime() . The method returns the number of milliseconds since the Unix Epoch and always uses UTC for time representation.
UTC() function in Go language is used to yield “t” with the location that is set to UTC. Moreover, this function is defined under the time package. Here, you need to import the “time” package in order to use these functions.
You can use time. Now(). UTC() if you'd rather have UTC than your local time zone.
The abbreviation UTC stands for Coordinated Universal Time or Temps Universal Coordonné and denotes the time, derived from atomic time, valid all over the world. This uses the 24-hour clock and the Gregorian Calendar as its standard. Note that this time always relates to Greenwich Mean Time, or GMT.
Unix()
always returns the number of seconds elapsed since January 1, 1970 UTC. So it does not matter whether you give it time.Now()
or time.Now().UTC()
, it is the same UTC time, just in different places on Earth. What you get as the result is correct.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With