private static TryParseDateTimeExact ( string text, DateTimeZoneHandling dateTimeZoneHandling, string dateFormatString, |
||
text | string | |
dateTimeZoneHandling | DateTimeZoneHandling | |
dateFormatString | string | |
culture | ||
dt | System.DateTime | |
return | bool |
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); }
internal static bool TryParseDateTime( StringReference s, DateTimeZoneHandling dateTimeZoneHandling, string dateFormatString, CultureInfo culture, out DateTime dt) { if (s.Length > 0) { int startIndex = s.StartIndex; if (s[startIndex] == '/') { if (s.Length >= 9 && s.StartsWith("/Date(") && (s.EndsWith(")/") && DateTimeUtils.TryParseDateTimeMicrosoft(s, dateTimeZoneHandling, out dt))) { return(true); } } else if (s.Length >= 19 && s.Length <= 40 && (char.IsDigit(s[startIndex]) && s[startIndex + 10] == 'T') && DateTimeUtils.TryParseDateTimeIso(s, dateTimeZoneHandling, out dt)) { return(true); } if (!string.IsNullOrEmpty(dateFormatString) && DateTimeUtils.TryParseDateTimeExact(s.ToString(), dateTimeZoneHandling, dateFormatString, culture, out dt)) { return(true); } } dt = new DateTime(); return(false); }