Created
April 5, 2011 16:43
-
-
Save prabirshrestha/903972 to your computer and use it in GitHub Desktop.
ISO8601 Date Time helpers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class DateTimeHelpers | |
{ | |
private static readonly string[] Iso8601Format = new[] | |
{ | |
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'", | |
@"yyyy-MM-dd\THH:mm:ssK" | |
}; | |
//SortableDateTimePattern (ISO 8601) | |
public static string ToIso8601(DateTime value) | |
{ | |
return value.ToUniversalTime().ToString(Iso8601Format[0], CultureInfo.InvariantCulture); | |
} | |
public static DateTime ParseIso8601(string value) | |
{ | |
return DateTime.ParseExact(value, Iso8601Format, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment