您当前位置:编程帮手 > 知识 > 知识 > C# > DateTime > 内容
代码库
2015-12-08 09:44:06 访问(1745) 赞(0) 踩(0)
/// <summary> /// 判断字符串HHmmss是否是有效的字符串时间 /// </summary> /// <param name="str"></param> /// <returns></returns> public bool TimeIsValidStr(string str) { if (str == null || str.Length == 0) return false; str = str.Trim(); if(str.Length ==0) return false; int iLen = str.Length; if (iLen != 6) return false; string strH = str.Substring(0, 2); string strM = str.Substring(2, 2); string strS = str.Substring(4, 2); int theValue = -1; if (!int.TryParse(strH, out theValue)) return false; if (theValue < 0 || theValue > 23) return false; if (!int.TryParse(strM, out theValue)) return false; if (theValue < 0 || theValue > 59) return false; if (!int.TryParse(strS, out theValue)) return false; if (theValue < 0 || theValue > 59) return false; return true; }
上一条:
下一条: