2017-06-15 77 views
0

我會嘗試格式化日期時間,例如Thu Jun 15 2017 14:12:28 GMT 0700 (SE Asia Standard Time),其格式類似於PHP中的2017-06-5。我用date_create但有errorl這樣如何在php中格式化日期時間

Warning: date_format() expects parameter 1 to be DateTimeInterface, string given 

,這我PHP代碼從$ 22

$aa = date_format($w22,"Y-m-d"); 

echo $aa; 

含量Thu Jun 15 2017 14:12:28 GMT 0700 (SE Asia Standard Time) 如何格式化日期時間像我,請幫我解決我的問題。由於

+0

我認爲這是因爲'GMT 0700(東南亞標準時間)'。這不是一個日期,這就是爲什麼'date_create()'什麼都不返回。嘗試回聲'$ w22' – Swellar

+0

我認爲[createfromformat](http://php.net/manual/en/datetime.createfromformat.php)可能有一些幫助? – Naruto

+0

試試這個日期('Y-m-d',strtotime($ date)); –

回答

1

您需要刪除GMT 0700 (SE Asia Standard Time)

$w22 = date_create("Thu Jun 15 2017 14:12:28") 
$aa = date_format($w22,"Y-m-d"); 

echo $aa; 
+0

你好吧,我忘了爆炸,謝謝你。 – Nugka

-1
<?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

這並不打算回答OP的問題 – Swellar