Epoch microseconds


Googling the internet I can’t find any way on how to convert this Unix epoch Timestamp (in microseconds) back to a date time format.

“startTimeUsecs”: 1540396800056886

Which should be: Wednesday, October 24, 2018 6:00:00.057 PM (Using www.epochconverter.com)

I’m also looking on how to convert any given date into the same format.


The number you have there is not in microseconds, but nanoseconds (1/1,000,000).

You can use time.Unix to parse a number into a time.Time, see https://golang.org/pkg/time/#Unix

Here is a playground example: https://play.golang.org/p/-x2QXiF_oM5

Thanks a lot !, now I just need to convert it to UTC+2.

If that is the local timezone on that machine you can use https://golang.org/pkg/time/#Time.Local

Thanks, I had already found out about that.

Perhaps you also know how to convert back from this date time format to epoch in nanoseconds ?

2018-10-23 18:00:00 +0200 CEST

Looks like your format string would be 2006-01-02 15:04:05 -0700 MST

This should help you out :slight_smile:

Ok thanks,

For now I am still stuck at this :slight_smile:

epoch to date

2018-10-24 18:00:00 +0200 CEST

date to epoch

2018-10-24 18:00:00 +0200 CEST

CEST := myTime.Local()

Good program but you removed the nanoseconds so one should really do like this:


Dividing the nanoseconds to get seconds and take the rest (modulo) and use them as nanoseconds in the call to time.Unix

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.