Optimizing alternatives to DateTime.Now

前端 未结 4 1145
隐瞒了意图╮
隐瞒了意图╮ 2020-12-29 04:36

A colleague and I are going back and forth on this issue and I\'m hoping to get some outside opinions as to whether or not my proposed solution is a good idea.

First

4条回答
  •  無奈伤痛
    2020-12-29 05:23

    One difference between the result of

    DateTime.Now
    

    and

    DateTime.UtcNow + LocalUtcOffset 
    

    is the value of the Kind property - Local vs Utc respectively. If the resultant DateTime is being passed to a third party library consider returning

    DateTime.SpecifyKind(DateTime.UtcNow + LocalUtcOffset, DateTimeKind.Local)
    

提交回复
热议问题