valid date check with DateTime.TryParse method

前端 未结 3 1940
旧时难觅i
旧时难觅i 2021-01-02 04:29

I am using Datetime.TryParse method to check the valid datetime. the input date string would be any string data. but is returning false as the specify date in i

3条回答
  •  甜味超标
    2021-01-02 04:41

    You should be using TryParseExact as you seem to have the format fixed in your case.

    Something like can also work for you

    DateTime.ParseExact([yourdatehere],
                        new[] { "dd/MM/yyyy", "dd/M/yyyy" },
                        CultureInfo.InvariantCulture,
                        DateTimeStyles.None);
    

提交回复
热议问题