java EXACTLY HH:MM:SS 时间字符串的正则表达式模式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25873636/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Regex pattern for EXACTLY HH:MM:SS time String
提问by ahmednabil88
I want to validate sting time format in EXACTLY hh:mm:ss
String.
I mean by EXACTLY that
Each of hours / minutes / seconds MUST be 2 digits
Also
Accept only logical valueslike
我想在 EXACTLY hh:mm:ss
String 中验证刺痛时间格式。
我的意思是确切地说,
每个小时/分钟/秒都必须是2 位数字
也
只接受逻辑值,例如
- hours [ from 00 to 23 ]
- minutes [ from 00 to 59 ]
- seconds [ from 00 to 59 ]
- 小时 [从 00 到 23]
- 分钟 [从 00 到 59]
- 秒 [从 00 到 59]
When i checked Regex pattern for HH:MM:SS time string
The answer accept hh:mm:ss
string but also accepts cases like 2:3:24
当我检查HH:MM:SS 时间字符串
的正则表达式模式时,答案接受hh:mm:ss
字符串但也接受类似的情况2:3:24
Thanks in advance
提前致谢
回答by Avinash Raj
回答by theftprevention
回答by null
The pattern you want is:
你想要的模式是:
(([0-1]?[0-9])|(2[0-3])):[0-5][0-9]:[0-5][0-9]
which is for HH:MM:SS
24hour format.
这是HH:MM:SS
24小时制。