How to check an UTC formatted date with a regular expression?

前端 未结 5 1446
星月不相逢
星月不相逢 2021-01-22 12:07

As you know the format is like:

\"YYYY-MM-DDTHH:NN:SS.ZZZ+XX:XX\"  (i.e. \"2009-03-24T16:24:32.057+01:00\")

I have to do it in a ActionScript3

相关标签:
5条回答
  • 2021-01-22 12:36

    Following Regex is perfect for any UTC date formats

    "^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\\.[0-9]+)?(Z)?$"
    

    Ref: https://www.regexpal.com/94925

    0 讨论(0)
  • 2021-01-22 12:43

    Regex should be something like this:

    \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}\+\d{2}:\d{2}
    
    0 讨论(0)
  • 2021-01-22 12:45

    Have a look at this related question:

    Actionscript 3 - Fastest way to parse yyyy-mm-dd hh:mm:ss to a Date object?

    The accepted answer provides a way to parse an UTC time string to a Date object.

    0 讨论(0)
  • 2021-01-22 12:46

    Java regex, tested to read a date like "2001-12-15T07:30:40Z":

    "^\\d{4}-[0-1][0-3]-[0-3]\\d{1}T[0-2]\\d{1}:[0-5]\\d{1}:[0-5]\\d{1}Z$"
    
    0 讨论(0)
  • 2021-01-22 12:48
    \d{4}-[0-1]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-6]\d.\d{3}\+\d\d:\d\d
    

    Or something similar?

    More checks of the valid range are probably better done after the reg.ex.

    0 讨论(0)
提交回复
热议问题