格式为{日-月-年}的单独日期


Separate date in the format {day-month-year}

我有一个以这种格式打印日期的代码Sun, 09 Mar 2014 08:31:14 GMT

我想把Date缩短以便打印

    一天
  • 月今年

但是我想分别打印每个并且我想以数字形式打印月份

下面是我试过的代码

$Date = $item->pubDate;
echo '.$Date.';

你应该利用DateTimeClass中的createFromFormat

<?php
$dt='Sun, 09 Mar 2014 08:31:14 GMT';
$date = DateTime::createFromFormat('D, d M Y G:i:s O', $dt);
echo "Day : ".$date->format('d'); // 09
echo "Month : ".$date->format('m'); //03
echo "Year : ".$date->format('Y'); //2014

尝试使用日期函数

echo date('d-m-Y', strtotime($Date));

如果你想一个一个回显

$date_to_time = strtotime($Date);
//Day
echo date('d', $date_to_time);
//Month
echo date('m', $date_to_time);
//Year
echo date('Y', $date_to_time);

Try

$date = '08/02/2014';
list($month, $day, $year) = explode('/', $date);