日期:2014-05-18 浏览次数:20870 次
TimeSpan ts1 = TimeSpan.Parse("06:00:00"); TimeSpan ts2 = TimeSpan.Parse("08:00:00"); TimeSpan ts = TimeSpan.Parse("07:00:00"); if(ts>=ts1 && ts<=ts2) { ... }
------解决方案--------------------
string str1 = "06:00:00";
string str2 = "08:00:00";
string strInput = "07:12:22";
DateTime dt1 = GetDateTime(str1);
DateTime dt2 = GetDateTime(str2);
DateTime dt3 = GetDateTime(strInput);
if (dt3 > dt2)
{
Console.WriteLine(dt3 + "大于" + dt2);
}
else
{
Console.WriteLine(dt3 + "小于等于" + dt2);
}
if (dt3 > dt1)
{
Console.WriteLine(dt3 + "大于" + dt1);
}
else
{
Console.WriteLine(dt3 + "小于等于" + dt1);
}
Console.ReadKey();
}
private static DateTime GetDateTime(string str)
{
if(str==null)return default(DateTime);
return DateTime.Parse(str);
}