参见英文答案 >
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');