2016-05-05 39 views
0

格式我有個約會:2015-06-24轉換YYYY-MM-DD格式的日期,以DD-MM使用PHP

我想它顯示爲24 June

我寫了這個代碼。

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

它顯示像結果:June 06

我在做什麼錯?

+1

使用'echo date('j -m',strtotime($ evnt_details ['events_date']));' –

+0

我的回答對你沒有幫助嗎? –

回答

5

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

$evnt_start_date = date('d F', strtotime($evnt_details['events_date'])); 
-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 
+0

感謝downvote送給我的好主意。 –

1

閱讀更多關於date()

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

這種格式這將輸出DD-MM

日期()格式化方法...

<?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) 
?> 
0

下面的代碼會給你24 June

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

上述許多問題的答案將工作就好了你,但我想提出一個真正真棒方式與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的正確途徑