Convert formatted date back to unix

2020-05-09 18:14发布

Which function would I use to convert custom formatted dates back to Unix Epoch time?

For example:

("Ymd") -> ("U");

I looked at date("U",strtotime("20140525")); , but I'm not sure how to fit in the original format Ymd.

How does that function know that the input format is YYYYMMDD, because it looks like it works.

Thanks

标签: php date time
1条回答
Ridiculous、
2楼-- · 2020-05-09 18:57

You can use DateTime::createFromFormat():

$date = DateTime::createFromFormat('Ymd', '20140525');
echo $date->format('U');
查看更多
登录 后发表回答