The output of this code will always be false, even if I give the date in the correct format. Please help me ... Here 2 parameters passed are time and format, i.e. (Format "HHMMSS").
static bool ValidateTime(string time, string format)
{
try
{
System.Globalization.DateTimeFormatInfo tinfo = new System.Globalization.DateTimeFormatInfo();
tinfo.LongTimePattern = format;
DateTime dt = DateTime.ParseExact(time, "format", tinfo);
if (dt.Hour != null)
{
}
return true;
}
catch (Exception e)
{
return false;
}
}
source
share