How can I format DateTime to web UTC format?

前端 未结 8 1933
梦毁少年i
梦毁少年i 2020-11-29 22:45

I have a DateTime which I want to format to \"2009-09-01T00:00:00.000Z\", but the following code gives me \"2009-09-01T00:00:00.000+01:00\" (both l

8条回答
  •  天命终不由人
    2020-11-29 23:28

    This code is working for me:

    var datetime = new DateTime(2017, 10, 27, 14, 45, 53, 175, DateTimeKind.Local);
    var text = datetime.ToString("o");
    Console.WriteLine(text);
    --  2017-10-27T14:45:53.1750000+03:00
    
    // datetime from string
    var newDate = DateTime.ParseExact(text, "o", null);
    

提交回复
热议问题