Convert multiple dates to Unix time in PHP
문제
Hi I have a few dates coming in random formats:
Wed, 16 Mar 2011 15:27:48 +0000
or
2011-03-16T17:42:05+0000
and I need to be able to convert them into Unix time in PHP. I assume I need to use mktime() , ,but how do I format my mktime ? I'm having trouble understanding the examples in the manual :/
Thanks
해결책
strtotime()
can work, but if the dates you're passing in are ambiguous (what is 01/02/03? Feb 1st, '03? Mar 2 '01?) it'll turn around and chew you a new one.
Safest option is to use date_create_from_format()
, which lets you specify an explicit format for the input.
다른 팁
제휴하지 않습니다 StackOverflow