格式日期dd / mm / yyyy to yyyy-mm-dd PHP

前端之家收集整理的这篇文章主要介绍了格式日期dd / mm / yyyy to yyyy-mm-dd PHP前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
参见英文答案 > Convert one date format into another in PHP11
我有一个表格,其中以英国格式输入日期,我需要将其转换为
yyyy-mm-dd

例如输入的日期是:31/03/2013我想转换为“2013-03-31”用于数据库插入.

我正在使用以下奇怪的作品,有时只是:

$dateInput = $MysqLi->real_escape_string($_POST['date']);
$show_date = date('Y-m-d',strtotime($dateInput));

有没有更好的方法来做到这一点?

你可能想要使用 DateTime::createFromFormat
$show_date = DateTime::createFromFormat('d/m/Y',$dateInput)->format('Y-m-d');

猜你在找的PHP相关文章