date format yyyy-MM-ddTHH:mm:ssZ

后端 未结 9 2272
走了就别回头了
走了就别回头了 2020-11-28 04:49

I assume this should be pretty simple, but could not get it :(. In this format Z is time zone.
T is long time pattern
How could I get a date in this format excep

9条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 05:08

    "o" format is different for DateTime vs DateTimeOffset :(

    DateTime.UtcNow.ToString("o") -> "2016-03-09T03:30:25.1263499Z"
    
    DateTimeOffset.UtcNow.ToString("o") -> "2016-03-09T03:30:46.7775027+00:00"
    

    My final answer is

    DateTimeOffset.UtcDateTime.ToString("o")   //for DateTimeOffset type
    DateTime.UtcNow.ToString("o")              //for DateTime type
    

提交回复
热议问题