Finding if a string contains a date and time

前端 未结 5 1174
渐次进展
渐次进展 2020-12-16 00:57

I am working on a project where I am reading in a file which could come in two different formats, one includes a date and time and the other doesn\'t.

When I read i

5条回答
  •  青春惊慌失措
    2020-12-16 01:40

    Use this method to check if string is date or not:

    private bool CheckDate(String date)
    {
        try
        {
            DateTime dt = DateTime.Parse(date);
            return true;
        }
        catch
        {
            return false;
        }
    }
    

提交回复
热议问题