I have an input timestamp from C# (.NET epoch: 00:00:00 (midnight), January 1, 0001) and I want to output it in Ruby world (Unix epoch: 00:00:00 UTC on 1 January 1970).
The input timestamp is given in UTC, and derived from .NET’s DateTime(Int64), which is “a date and time expressed in the number of 100-nanosecond intervals that have elapsed since January 1, 0001 at 00:00:00.000 in the Gregorian calendar.“
The input timestamp: 634891434586852680
Output should be 2012-NOV-21 a bit after 5pm PST.
In Ruby, Time is stored internally as the number of seconds with fraction since the Epoch, January 1, 1970 00:00 UTC. Therefore we must convert from
100-nanosecond intervalstoseconds.The conversion factor of
1e-7is1e2/1e9which is100/1000000000which can be explained as:The
intervalscancel themselves out, as do thenanoseconds, and we are left withseconds; and100/1000000000 secondsis1e2/1e9 secondswhich is1e-7 seconds.