Check if a string is a valid date using DateTime.TryParse

前端 未结 6 1987
梦谈多话
梦谈多话 2020-11-30 05:27

I am using DateTime.TryParse() function to check if a particular string is a valid datetime not depending on any cultures.
To my surprise , the function re

6条回答
  •  感动是毒
    2020-11-30 06:07

    So this question has been answered but to me the code used is not simple enough or complete. To me this bit here is what I was looking for and possibly some other people will like this as well.

    string dateString = "198101";
    
    if (DateTime.TryParse(dateString, out DateTime Temp) == true)
    {
         //do stuff
    }
    

    The output is stored in Temp and not needed afterwards, datestring is the input string to be tested.

提交回复
热议问题