2011-08-02 33 views
1

當我有UNIX時間戳,我會寫:strftime在日期?

strftime("%A", $date) 

但現在我有日戳,如「2011-08-02」

我怎樣才能使它輸出的平日名稱,例如「星期日」?

回答

0

使用date('l');添加更多屬性,如:date('l d-m-Y');

更多信息here

2

您可以將日期戳轉換爲使用功能strtotime時間戳。 獲得時間戳後,您可以使用功能date以所需格式顯示日期。

+0

例如: date(「g:i a F j Y」,strtotime(time())); //將打印上午10點20分2011年7月20日 – gerarddp

+0

'日期'vs'strftime'與問題無關。 –

0

(2日2011年8月是星期二,不是星期日)


<?php 
echo strftime("%A", strtotime("2011-08-02")); 
// Output: "Tuesday" 
?> 
0
date('l',strtotime('2011-08-02')); 
1

首先使用strtotime功能轉換的「2011-08-02」到UNIX時間戳,然後繼續爲你通常會

例如,下面的是等價的:

$date = 1312243200; // A unix timestamp 
$date = strtotime('2011-08-02'); // The date that it represents 

然後,您可以做任何你通常會用結果做

的的strtotime()函數是相當寬容它是接受的日期格式,甚至接受數值,如「晚上8點明天」或「上週一」 - 見http://www.php.net/strtotime

+0

更好的'$ date = strtotime('2011-08-02')'對稱 –

+0

同意。也使答案更一般。 – Jim

+0

這好多了:D +1 –

相關問題