regular expression for time

后端 未结 3 1162
别跟我提以往
别跟我提以往 2021-01-18 05:33

I want regular expression for HH:MM:SS AM/PM here HH must be 1-12 only, MM must 60 min, SS as usual (60 sec.) I any have it properly ...?

相关标签:
3条回答
  • 2021-01-18 06:03

    If you want to be able to have the zero padding as optional as well as leap seconds:

    /^((0?[1-9])|(1[0-2])):[0-5]\d:(([0-5]\d)|(60)) [AP]M$/
    

    The breakdown:
    (0?[1-9]|1[0-2]) 1-9 (with optional leading zero) or 10-12
    [0-5][0-9] 00-59 (0-5 for first digit, 0-9 for second)
    ([0-5][0-9])|(60) Leap seconds
    [AP]M AM/PM

    0 讨论(0)
  • 2021-01-18 06:16
    /^([1-9]|10|11|12):[0-5][0-9]:[0-5][0-9] [AP]M$/
    
    0 讨论(0)
  • 2021-01-18 06:24
    (0[1-9]|1[0-2]):([0-5][0-9]:[0-5][0-9]|(59|44|29):60) (AM|am|PM|pm)
    
    0 讨论(0)
提交回复
热议问题