title: How to solve DateTimeInvalidLocalFormat error: "A UTC DateTime is being converted to text in a format that is only correct for local times."?
body: <p>I am getting this error while in Debug though the ToString() is executed:</p>
  
  <blockquote>
    <p>A UTC DateTime is being converted to text in a format that is only
    correct for local times. This can happen when calling
    DateTime.ToString using the 'z' format specifier, which will include a
    local time zone offset in the output. In that case, either use the 'Z'
    format specifier, which designates a UTC time, or use the 'o' format
    string, which is the recommended way to persist a DateTime in text.
    This can also occur when passing a DateTime to be serialized by
    XmlConvert or DataSet. If using XmlConvert.ToString, pass in
    XmlDateTimeSerializationMode.RoundtripKind to serialize correctly. If
    using DataSet, set the DateTimeMode on the DataColumn object to
    DataSetDateTime.Utc.</p>
  </blockquote>
  
  <pre><code>public static string ToInterfaceString(this DateTime value)
  {
      return value != DateTime.MinValue ? value.ToString("yyyy-MM-ddTHH:mm:sszzz") : string.Empty;
  }
  </code></pre>
  
  <p>In the app that I've just starting to work on it is used this format in many places. So what should I do in fact? Replace zzz with Z?</p>
  
  <p>Update 1:
  the DateTime that is passed to my extension is initiated to:</p>
  
  <pre><code>DateTimeCreated = DateTime.UtcNow;
  </code></pre>
  
  <p>Weird thing is that if I pass to this extension some other DateTime objects I don't receive any error/warning.</p>