{day-month-year}格式的单独日期

时间:2014-03-10 08:30:32

标签: php function datetime output

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

我想把日期缩短,以便打印

  • 这一天
  • 月份
  • 年度

但我想分开打印,我想用数字打印月份

这是我试过的代码

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

3 个答案:

答案 0 :(得分:3)

您应该使用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

Demo

答案 1 :(得分:1)

尝试使用date功能

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);

答案 2 :(得分:0)

尝试

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