DateTimeParser.TryParse C# (CSharp) Method

TryParse() public static method

public static TryParse ( string str, DateTime, &result ) : bool
str string
result DateTime,
return bool
    public static bool TryParse(string str, out DateTime result) => DateTime.TryParse(
        str,
        null,
        DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal,
        out result);

Usage Example

Ejemplo n.º 1
0
        private bool TryParseDateTime(string text, out DateTime result)
        {
            bool isValid = false;

            result = this.ContextNow;

            DateTime current = this.ContextNow;

            try
            {
                // TempValue is used when Manipulating TextBox.Text while Value is not updated yet (used in DateTimePicker's TimePicker).
                current = this.TempValue.HasValue
                          ? this.TempValue.Value
                          : this.Value.HasValue ? this.Value.Value : DateTime.Parse(this.ContextNow.ToString(), this.CultureInfo.DateTimeFormat);

                isValid = DateTimeParser.TryParse(text, this.GetFormatString(Format), current, this.CultureInfo, this.AutoClipTimeParts, out result);
            }
            catch (FormatException)
            {
                isValid = false;
            }

            if (!isValid)
            {
                isValid = DateTime.TryParseExact(text, this.GetFormatString(this.Format), this.CultureInfo, DateTimeStyles.None, out result);
            }

            if (!isValid)
            {
                result = (_lastValidDate != null) ? _lastValidDate.Value : current;
            }

            return(isValid);
        }
All Usage Examples Of DateTimeParser::TryParse