/// <summary> /// Parses the input date time offset string of the specified format. /// </summary> public static DateTimeOffset ParseDateTimeOffset( string dateTime, StandardDateTimeFormat format) { return(DateTimeOffset.ParseExact( dateTime, GetFormat_(format), CultureInfo.InvariantCulture)); }
/// <summary> /// Returns a string representation of the input date time of the specified /// format. /// </summary> public static string ToString(this DateTime dateTime, StandardDateTimeFormat format) { if (format == StandardDateTimeFormat.RFC1123 && dateTime.Kind != DateTimeKind.Utc) { dateTime = dateTime.ToUniversalTime(); } return(dateTime.ToString(GetFormat_(format), CultureInfo.InvariantCulture)); }
/// <summary> /// Returns a string representation of the input date time offset of the specified /// format. /// </summary> public static string ToString(this DateTimeOffset dateTime, StandardDateTimeFormat format) { if (format == StandardDateTimeFormat.RFC1123 && dateTime.Offset != TimeSpan.Zero) { dateTime = dateTime.ToUniversalTime(); } return(dateTime.ToString(GetFormat_(format), CultureInfo.InvariantCulture)); }
/// <summary> /// Parses the input date time string of the specified format. /// </summary> public static DateTime ParseDateTime( string dateTime, StandardDateTimeFormat format, DateTimeKind kind = DateTimeKind.Unspecified) { var parsed = DateTime.ParseExact( dateTime, GetFormat_(format), CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind); if (parsed.Kind == DateTimeKind.Unspecified) { parsed = DateTime.SpecifyKind(parsed, kind); } return(parsed); }
private static string GetFormat_(StandardDateTimeFormat format) { if (format == StandardDateTimeFormat.RFC1123) { return(RFC1123Format_); } if (format == StandardDateTimeFormat.RFC3339) { return(RFC3339Format_); } if (format == StandardDateTimeFormat.ISO8601) { return(ISO8601_Short_Format_); } throw new NotImplementedException("Unknown format: {0}".Fmt(format)); }