PHP更改日期格式(日期来自MySQL's 'CURRENT_TIMESTAMP')


PHP change date format (date coming from MySQL's 'CURRENT_TIMESTAMP'

我尝试了一些方法,但到目前为止都没有成功。

我想让yyyy-mm-dd的日期看起来像mm/dd/yyyy

初始值示例,取自MySQL: 2015-08-21 14:46:00

这是我得到的:

foreach ($draftOrders as $key => $value) {
    $timestamp = strtotime($value['last_modified']);
    // this one works (leaving it unchanged)
    // however the slashes are not replacing the dash
    // $new_date_format = date('Y/m/d H:i:s', $timestamp);
    // fails, date becomes 1970-01-01 12:00 am
    $new_date_format = date('m/d/Y H:i:s', $timestamp);
    $draftOrders[$key]['last_modified'] = $new_date_format;
}

要在mysql中执行这种日期格式化,您可能需要查看以下内容:-

select date_format(`date`,'%Y/%m/%e %H:%i:%s') from `table`

try this

 echo date('m/j/Y', strtotime('2015-08-21 14:46:00'));
http://php.net/manual/en/function.date.php