What is the standard format for datetime with timezone in a C# ASP.NET application?
Updated to clarify: In ASP.NET I need to check a datetime from a Domino database against a .NET DateTime. The client is asking what would be the best format in which he should provide the datetime with the timezone. Meaning which format is most easily readable by .NET?
Update – regarding your clarification:
.NET supports parsing a wide variety of different formats so as long as it is in a fairly standard unambiguous format you should have no problem parsing it. But don’t leave it to chance by relying on the default settings, use ParseExact or TryParseExact.
Check out the following resource for details on constructing the format string:
If you want to suggest something to him, then I would recommend following the ISO 8601 standard, which looks something like this:
2010-05-14T10:04Z.DateTime.Parsecan also understand this format without needing to provide a format string.Answering your original question:
Default formatting of DateTimes is based on the current locale. If you want a consistant format use either
CultureInfo.InvariantCultureor else a specific culture of your choice.Result:
Note that the default formatting doesn’t include the time zone. You can specify your own formatting though:
Result: