private static bool TryParseDateTimeExact( string text, DateTimeZoneHandling dateTimeZoneHandling, string dateFormatString, CultureInfo culture, out DateTime dt) { DateTime result; if (DateTime.TryParseExact(text, dateFormatString, (IFormatProvider)culture, DateTimeStyles.RoundtripKind, out result)) { DateTime dateTime = DateTimeUtils.EnsureDateTime(result, dateTimeZoneHandling); dt = dateTime; return(true); } dt = new DateTime(); return(false); }
internal static bool TryParseDateTime( string s, DateTimeZoneHandling dateTimeZoneHandling, string dateFormatString, CultureInfo culture, out DateTime dt) { if (s.Length > 0) { if (s[0] == '/') { if (s.Length >= 9 && s.StartsWith("/Date(", StringComparison.Ordinal) && (s.EndsWith(")/", StringComparison.Ordinal) && DateTimeUtils.TryParseDateTimeMicrosoft(new StringReference(s.ToCharArray(), 0, s.Length), dateTimeZoneHandling, out dt))) { return(true); } } else if (s.Length >= 19 && s.Length <= 40 && (char.IsDigit(s[0]) && s[10] == 'T') && DateTime.TryParseExact(s, "yyyy-MM-ddTHH:mm:ss.FFFFFFFK", (IFormatProvider)CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out dt)) { dt = DateTimeUtils.EnsureDateTime(dt, dateTimeZoneHandling); return(true); } if (!string.IsNullOrEmpty(dateFormatString) && DateTimeUtils.TryParseDateTimeExact(s, dateTimeZoneHandling, dateFormatString, culture, out dt)) { return(true); } } dt = new DateTime(); return(false); }