DateTime vs DateTimeOffset

前端 未结 10 1830
刺人心
刺人心 2020-11-22 00:23

Currently, we have a standard way of dealing with .NET DateTime\'s in a TimeZone aware way: Whenever we produce a DateTime we do it in UTC (e.g. us

10条回答
  •  北海茫月
    2020-11-22 00:36

    TLDR if you don't want to read all these great answers :-)

    Explicit:

    Using DateTimeOffset because the timezone is forced to UTC+0.

    Implicit:

    Using DateTime where you hope everyone sticks to the unwritten rule of the timezone always being UTC+0.


    (Side note for devs: explicit is always better than implicit!)

    (Side side note for Java devs, C# DateTimeOffset == Java OffsetDateTime, read this: https://www.baeldung.com/java-zoneddatetime-offsetdatetime)

提交回复
热议问题