我有一个日期:2015-06-24
我想将其显示为24 June
我已经写了这个代码。
$evnt_start_date = date('F m', strtotime($evnt_details['events_date']));
显示结果如下:June 06
我做错了什么?
m
是月数。按相反顺序使用d
:
$evnt_start_date = date('d F', strtotime($evnt_details['events_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)
?>
下面的代码将为您提供24 June
。
date("d F",strtotime($evnt_details['events_date']));
上面的许多答案对您来说都很好,但我想推荐一种在PHP中使用日期和时间的非常棒的方法。它是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正确的方式
使用j
表示不前导0,使用d
表示前导0。
非前导零:
$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