DateTime <--> EPOC conversions

Can you explain what the differences are between:

  • ToUnixTime()
  • ToUnixTimeMs()
  • ToUnixTimeMsAlt()

In Windows fat clients I use DateTimeOffset.FromUnixTimeMilliseconds(long with milliseconds);
I get data from another application through RabbitMQ. We agreed to use EPOC as format for Timestamps of any kind.

I just wonder which of the three methods you offer are ‘compatible’ with the one I use from the DateTimeOffset class. Is ToUnixTime() in seconds or also milliseconds?
Thanks.

The source code for the the 3 impls are here:

Unix Time is typically the number of secs from Unix Epoch UTC but sometimes it’s stored as the number of ms since Unix Epoch. You’ll need to find out what they’re using.

The ToUnixTimeMsAlt() is an alt impl that uses platform available APIs to convert from a non-UTC Date to UTC before calculating time since Epoch. To avoid the differences in different .NET platforms convert the date to UTC yourself before calling ToUnixTime(), then just call ToUnixTime() or ToUnixTimeMs() which wont need to do any DateTime UTC conversions.

Ok, so I have to use ToUnixTimeMs() to be compatible with what I do on Windows. Thanks!

1 Like