我想将上述格式的日期转换为等效的Unix时间戳。我搜索了很多,但没有得到任何解决方案。有人能帮我解决这个问题吗?
又快又脏:
$pieces = explode("/", "11/03/2013");
echo strtotime($pieces[1]."/".$pieces[0]."/".$pieces[2]);
我认为你需要使用这个strtotime($date);
试试这个strtotime (11/03/2013);
strtotime('Jun 26,12');
如果分隔符是斜杠(/),则假定美制m/d/y;而如果分隔符是破折号(-)或点(.),则采用欧洲d-m-y格式。
strtotime( str_replace( '/', '-', '11/03/2013') ) );
你可以找到更多的细节在…
如果你有一个非常特殊的格式,那么使用DateTime
DateTime::createFromFormat('11-2013.03', 'd-Y.m')->getTimestamp()
如果是普通日期格式,则使用strtotime()
PHP>= 5.2
$date = DateTime::createFromFormat('d/m/Y', '11/03/2013');
echo $date->format('U');
$date = DateTime::createFromFormat('d/m/Y', '11/03/2013');
echo $date->getTimestamp();