locked
Detect the problem RRS feed

  • Question

  • Hi,
    How to detect the problem with the time, like
    25:40

    by enhancing these codes
                string format="t";
                    try
                    {
                        System.Globalization.CultureInfo provider = System.Globalization.CultureInfo.InvariantCulture;
                        DateTime dt = DateTime.ParseExact(tb_start.Text.Trim(), format, provider);
                        if (dt.Hour == null)
                        {
                            ...
                        }
                    }
                    catch (Exception ex)
                    {
                        ...



    for finding out the input problem there?

    Many Thanks & Best Regards, Hua Min

    Tuesday, April 22, 2014 6:27 AM

Answers

All replies

  • It is simple.

    Use DateTime.TryParse() method.

    See below link for more information.

    http://msdn.microsoft.com/en-us/library/ch92fbc1.aspx

    Hope This Helps... :)

    • Proposed as answer by SekThang Tuesday, April 22, 2014 7:04 AM
    • Marked as answer by Jackson_1990 Tuesday, April 22, 2014 7:24 AM
    Tuesday, April 22, 2014 6:49 AM
  • How to detect the problem with the time, like
    25:40

    by enhancing these codes
                string format="t";
                    try
                    {
                        System.Globalization.CultureInfo provider = System.Globalization.CultureInfo.InvariantCulture;
                        DateTime dt = DateTime.ParseExact(tb_start.Text.Trim(), format, provider);
    

    That will throw an exception. If you don't want an exception, then look at TryParseExact()
    and TryParse().

    - Wayne



    • Edited by WayneAKing Tuesday, April 22, 2014 7:14 AM
    Tuesday, April 22, 2014 6:50 AM