How to convert date to timestamp in PHP?

前端 未结 19 1898
暗喜
暗喜 2020-11-22 05:38

How do I get timestamp from e.g. 22-09-2008?

19条回答
  •  -上瘾入骨i
    2020-11-22 06:34

    Be careful with functions like strtotime() that try to "guess" what you mean (it doesn't guess of course, the rules are here).

    Indeed 22-09-2008 will be parsed as 22 September 2008, as it is the only reasonable thing.

    How will 08-09-2008 be parsed? Probably 09 August 2008.

    What about 2008-09-50? Some versions of PHP parse this as 20 October 2008.

    So, if you are sure your input is in DD-MM-YYYY format, it's better to use the solution offered by @Armin Ronacher.

提交回复
热议问题