PHP validate ISO 8601 date string

后端 未结 5 1575
半阙折子戏
半阙折子戏 2020-12-15 06:02

How do you validate ISO 8601 date string (ex: 2011-10-02T23:25:42Z).

I know that there are several possible representations of ISO 8601 dates, but I\'m only interest

5条回答
  •  隐瞒了意图╮
    2020-12-15 06:36

    This worked for me, it uses a regular expression to make sure the date is in the format you want, and then tries to parse the date and recreate it to make sure the output matches the input:

    You could expand further to use checkdate to make sure the month day and year are valid as well.

提交回复
热议问题