用于日期时间格式的正则表达式 [英] RegEx for date time format
本文介绍了用于日期时间格式的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用以下格式的日期时间正则表达式
Hi,
I would like to have a regular expression for the date time in the below formats
mm/dd/yyyy HH:MM:SS AM/PM
mm/dd/yyyy HH:MM AM/PM
问候,
Vipul
Regards,
Vipul
推荐答案
而不是重新发明轮子,请参阅 ^ ],它具有类似的表达式.请注意:它们很复杂,因此,如果它们不能完全满足您的需求,那么您的工作将会很漫长.获取 Expresso [ ^ ]它是免费的,可以真正帮助调试正则表达式!
我不知道您要达到什么目的,但是使用 DateTime.ParseExact [ ^ ]代替...
Rather than re-invent the wheel, see http://regexlib.com/DisplayPatterns.aspx?cattabindex=4&categoryId=5[^] which has similar expressions. Be warned though: they are complex, so if they don;t fit your need exactly, then you have a long job ahead. Get a copy of Expresso[^] it''s free and can really help debug a regex!
I don''t know what you are trying to achieve, but you may be better off using DateTime.ParseExact[^] instead...
^((((31\/(0?[13578]|1[02]))|((29|30)\/(0?[1,3-9]|1[0-2])))\/(1[6-9]|[2-9]\d)?\d{2})|(29\/0?2\/(((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))|(0?[1-9]|1\d|2[0-8])\/((0?[1-9])|(1[0-2]))\/((1[6-9]|[2-9]\d)?\d{2})) (20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d
希望对您有所帮助.
Hope this can help you.
这篇关于用于日期时间格式的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文