Gum*_*mbo 41
试试这个正则表达式:
^(?:[01]?[0-9]|2[0-3]):[0-5][0-9]$
Run Code Online (Sandbox Code Playgroud)
或者更加明显:
^(?:0?[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$
Run Code Online (Sandbox Code Playgroud)
我不想偷任何人的辛勤工作,但显然这正是你所寻找的.
using System.Text.RegularExpressions;
public bool IsValidTime(string thetime)
{
Regex checktime =
new Regex(@"^(20|21|22|23|[01]d|d)(([:][0-5]d){1,2})$");
return checktime.IsMatch(thetime);
}
Run Code Online (Sandbox Code Playgroud)
我只使用DateTime.TryParse().
DateTime time;
string timeStr = "23:00"
if(DateTime.TryParse(timeStr, out time))
{
/* use time or timeStr for your bidding */
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
37577 次 |
| 最近记录: |