使用PHP将YYYY-mm-dd格式的日期转换为dd-mm格式

时间:2016-05-05 10:41:32

标签: php

我有一个日期:2015-06-24

我想将其显示为24 June

我已经写了这段代码。

$evnt_start_date = date('F m', strtotime($evnt_details['events_date']));

它显示的结果如下:June 06

我做错了什么?

5 个答案:

答案 0 :(得分:5)

m是月份。以相反的顺序使用d

$evnt_start_date = date('d F', strtotime($evnt_details['events_date']));

答案 1 :(得分:1)

详细了解date()

<?php
    echo date('d F', strtotime($evnt_details['events_date']));
?>

这将以此格式输出DD-MM

date()格式化方法......

<?php
// Assuming today is March 10th, 2001, 5:16:18 pm, and that we are in the
// Mountain Standard Time (MST) Time Zone

$today = date("F j, Y, g:i a");                 // March 10, 2001, 5:16 pm
$today = date("m.d.y");                         // 03.10.01
$today = date("j, n, Y");                       // 10, 3, 2001
$today = date("Ymd");                           // 20010310
$today = date('h-i-s, j-m-y, it is w Day');     // 05-16-18, 10-03-01, 1631 1618 6 Satpm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.');   // it is the 10th day.
$today = date("D M j G:i:s T Y");               // Sat Mar 10 17:16:18 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h');     // 17:03:18 m is month
$today = date("H:i:s");                         // 17:16:18
$today = date("Y-m-d H:i:s");                   // 2001-03-10 17:16:18 (the MySQL DATETIME format)
?>

答案 2 :(得分:0)

下面的代码会为您提供24 June

date("d F",strtotime($evnt_details['events_date']));

答案 3 :(得分:0)

上面的许多答案对你来说都很合适,但是我想建议一个非常棒的方式来使用PHP中的Dates和Time。它的DateTime及其相关课程;回答你的问题:

$dateString = '2015-06-24';
$date = new \DateTime($dateString);
$evnt_start_date = $date->format('d F');

请参阅以下链接:

http://php.net/manual/en/class.datetime.php - 日期时间

一些额外的阅读将有助于现在和将来:
http://www.phptherightway.com/#date_and_time - PHP正确的方式

答案 4 :(得分:-1)

使用j表示不领先0,使用d表示领先零。

不领先零:

$evnt_details['events_date'] = '2015-06-24';
echo $evnt_start_date = date('j F', strtotime($evnt_details['events_date']));//24 June

领先零:

$evnt_details['events_date'] = '2015-06-24';
echo $evnt_start_date = date('d F', strtotime($evnt_details['events_date']));//24 June