How can I format DateTime to web UTC format?

.net, c#, datetime, utc

Solution

string foo = yourDateTime.ToUniversalTime()
                         .ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");

Problem

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 lines): ``` new DateTime(2009, 9, 1, 0, 0, 0, 0, DateTimeKind.Utc).ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffzzz") new DateTime(2009, 9, 1, 0, 0, 0, 0, DateTimeKind.Utc).ToUniversalTime().ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffzzz") ``` Any ideas how to make it work?

Original source

Related problems