Recognise an arbitrary date string

后端 未结 14 903
抹茶落季
抹茶落季 2020-12-01 16:18

I need to be able to recognise date strings. It doesn\'t matter if I can not distinguish between month and date (e.g. 12/12/10), I just need to classify the string as being

14条回答
  •  无人及你
    2020-12-01 16:25

    Maybe you should use regular expressions?

    Hopefully this one would work for mm-dd-yyyy format:

    ^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$

    Here (0[1-9]|1[012]) matches the month 00..12, (0[1-9]|[12][0-9]|3[01]) matches a date 00..31 and (19|20)\d\d matches a year.

    Fields can be delmited by dash, slash or a dot.

    Regards, Serge

提交回复
热议问题