Convert UTC DateTime to DateTimeOffset

后端 未结 3 1190
谎友^
谎友^ 2020-12-16 10:51

I need to convert UTC date strings to DateTimeOffsets.

This must work with a timezone which differs from the computers timezone.

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-16 11:00

    const String dateString = "2012-11-20T00:00:00Z"; 
    var offsetDate = DateTimeOffset.Parse(dateString); 
    var offsetDate2 = DateTime.Parse(dateString);
    

    Output is

    offsetDate  {20-11-2012 0:00:00 +00:00}    System.DateTimeOffset
    offsetDate2 {20-11-2012 1:00:00}           System.DateTime
    

提交回复
热议问题