If I execute the following PowerShell script:
$> ([DateTime]"2023-10-16T16:56:14.052Z" - [DateTime]"1970-01-01T00:00:00.000Z").TotalMilliseconds
It gives the result (based on the TimeSpan object):
1697478974052
However, if use the DateTimeOffset object instead:
$> ([DateTimeOffset]"2023-10-16T16:56:14.052Z").ToUnixTimeMilliseconds
I get a different result which appears to be exactly 3600000 milliseconds off (exactly 1 hour). However, this appears to be the correct number of milliseconds since epoch (1970-01-01T00:00:00Z).
1697475374052
I had expected both commands to yield the same number of milliseconds. It makes it appear that TimeSpan is incorrectly calculating the number of milliseconds. What am I missing?
When the time is exactly one hour off, it screams day light savings to me. In the first command with [DateTime]
its probably taking in your local machine's timezone's daylight saving configuration (1 hour ahead).
The second command is taking the time in UTC as shown here. UTC has no daylight savings because it serves as a constant frame of reference in which other time zones are relative.