developer155
Programmer
Hi, I need a way to make sure that user entered time is in 24 hour format, like 23:55 for 11:55 PM
I got stuck, my code is below. Thanks for any help
public bool ValidTime(string strTime)
{
bool lValid = false;
if(strTime != null && strTime != "")
{
try
{
System.Globalization.DateTimeFormatInfo dateFormat = new System.Globalization.DateTimeFormatInfo();
dateFormat.LongTimePattern = "HH:mm:ss";
DateTime dt = DateTime.Parse(strTime, dateFormat);
lValid = true;
}
catch
{
// we failed
lValid = false;
}
}
else
{
lValid = true;
}
return lValid;
}
I got stuck, my code is below. Thanks for any help
public bool ValidTime(string strTime)
{
bool lValid = false;
if(strTime != null && strTime != "")
{
try
{
System.Globalization.DateTimeFormatInfo dateFormat = new System.Globalization.DateTimeFormatInfo();
dateFormat.LongTimePattern = "HH:mm:ss";
DateTime dt = DateTime.Parse(strTime, dateFormat);
lValid = true;
}
catch
{
// we failed
lValid = false;
}
}
else
{
lValid = true;
}
return lValid;
}