Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Or, equivalently,

    $utc = [DateTimeOffset]::FromUnixTimeSeconds(16e8).UtcDateTime
Incidentally,

    PS> ($utc, (Get-Date -AsUtc '1/1/1970'), (Get-Date -AsUtc), (Get-Date)).Kind
    Utc
    Utc
    Utc
    Local
In your example,

    $naive.Kind -eq [DateTimeKind]::Unspecified
correctly, because no DateTimeKind was specified.

The peculiar behavior you observed with ToLocationTime and ToUniversalTime exists to avoid breaking changes in working[1] code written for versions of the .NET Framework before 2.0, where DateTime.Kind was introduced (as was DateTimeOffset, so ToLocationTime and ToUniversalTime should probably be deprecated).

[1] "Breaking" changes exist for already-broken code, e.g., in Framework 2.0 and later, the return values of ToUniversalTime and ToLocalTime have Kinds Utc and Local, respectively, so applying the same conversion to an already-converted value no longer has any effect.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: