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
2009-09-01T00:00:00.000Z
2009-09-01T00:00:00.000+01:00
You want to use DateTimeOffset class.
var date = new DateTimeOffset(2009, 9, 1, 0, 0, 0, 0, new TimeSpan(0L)); var stringDate = date.ToString("u");
sorry I missed your original formatting with the miliseconds
var stringDate = date.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");