将“YYYY月份日期”转换为YYYY-MM-DD Php

时间:2015-06-10 13:08:17

标签: php date datetime

如何将“2015年3月20日星期五”转换成“2015-03-20”的Php?

尝试的选项(失败):

$time = strtotime(stripslashes("Friday 20th of March 2015"));
echo date("Y-m-d",$time);


$time = strtotime("Friday 20th of March 2015");
echo date("Y-m-d",$time);

选项2(失败):

$old_date = date('Friday 20th of March 2015');           
$old_date_timestamp = strtotime($old_date);
$new_date = date('Y-m-d', $old_date_timestamp);   
echo $new_date;

选项3(失败):

$date = DateTime::createFromFormat('l d of F Y', 'Friday 20th of March 2015');
$new_date_format = $date->format('Y-m-d');
echo $new_date_format;

没有解决的重复条目: How to convert "Day, dd Month yyyy" to "yyyy-mm-dd" in php

Convert one date format into another in PHP

1 个答案:

答案 0 :(得分:1)

本守则有效:

$date = DateTime::createFromFormat('l dS \o\f F Y', 'Friday 20th of March 2015');
        $new_date_format = $date->format('Y-m-d');
        echo $new_date_format;