读书人

判断字符串是时间(hh:mm)格式?解决

发布时间: 2012-04-10 21:03:56 作者: rapoo

判断字符串是时间(hh:mm)格式?
只有时和分(hh:mm)


08:19
23:59
23:59
9:1
9:01
09:1
00:00
0:0
是正确的

24:01
25:00
0:60
是错误的

[解决办法]
我会考虑用 DataTime.TryParse 来解析。前面固定拼上 "2012/1/1"
[解决办法]

探讨

我会考虑用 DataTime.TryParse 来解析。前面固定拼上 "2012/1/1"

[解决办法]
C# code
            string source = @"23:60";            Regex reg = new Regex(@"[0-23]+:[0-59]+");            Match mm = reg.Match(source);
[解决办法]
VB.NET code
Dim source As String = "23:60"Dim reg As New Regex("[0-23]+:[0-59]+")Dim mm As Match = reg.Match(source) 

读书人网 >VB Dotnet

热点推荐