title: How Do I Serialize DateTime Objects in .NET in a Standards Compliant Way
body: <p>My goal is use the .NET DateTime object (in C#) and have that be serialized to and parsed from a string (for use in XML) in a way that is standards compliant. The specific standard I have in mind is the ISO 8601 standard for representing dates and times.</p>
  
  <p>I want an easy to use solution (preferably, one method call each way)
   that will convert to and from the concatenated version of the format. I would also like to preserve local time zone information.</p>
  
  <p>Here's an example of the sort of string I'd like to get:</p>
  
  <p>2009-04-15T10:55:03.0174-05:00</p>
  
  <p>My target .NET version is 3.5.</p>
  
  <p>I actually found a solution to this problem several years ago which involves a custom format and the DateTime.ToString(string) method. I was surprised that a simpler standards compliant solution didn't exist. Using a custom format string to serialize and parse in a standards compliant way smells a little to me.</p>