Skip to content

Instantly share code, notes, and snippets.

@codereflection
Created March 23, 2012 17:29
Show Gist options
  • Save codereflection/2173032 to your computer and use it in GitHub Desktop.
Save codereflection/2173032 to your computer and use it in GitHub Desktop.
/// <summary>
/// Convert to ISO 8601 Date time format (Required by Sqlite)
/// </summary>
/// <param name="dateTime">date to convert</param>
/// <returns>date converted to ISO8601 datetime format</returns>
public static string ToISO8601(this DateTime dateTime)
{
return dateTime.ToString("u").Replace("Z", "");
}
public static string ToISO8601(this DateTime? dateTime)
{
if(dateTime.HasValue)
return dateTime.Value.ToString("u").Replace("Z", "");
return DateTime.MinValue.ToISO8601();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment