Why doesn't DateTime.ParseExact parse UTC format with the trailing Z?

前端 未结 1 1795
旧时难觅i
旧时难觅i 2020-12-31 11:11

Another ParseExact problem. I\'m trying to parse a UTC formatted string to a datetime with the format of:

\"YYYY-MM-DDThh:mm:ss.ssZ\"

which is i

相关标签:
1条回答
  • 2020-12-31 11:14

    The format strings you mentioned are standard format strings. You should probably use a custom format string, like this:

    DateTime.ParseExact("2011-03-02T20:15:19.64Z", "yyyy-MM-ddTHH:mm:ss.ffK", null).ToUniversalTime()
    

    If you don't put ToUniversalTime() at the end, the result will be converted to your local time zone.

    0 讨论(0)
提交回复
热议问题