2011-11-04 25 views

回答

0

我解決這個與此代碼:在我看來

<?php 
    $date_of_post = $r->date_nw;  
    $date = $date_of_post; // 6 october 2011 2:28 pm 
    $stamp = strtotime($date); // outputs 1307708880 
    ?> 

    <?php echo date("d", $stamp); ?> // it prints out the day only 
    <?php echo date("M", $stamp); ?> // it prints out the Month only like (Oct) 
2

您可以使用date & time functions of MySQL或PHP的功能,如strtotime()

例如,對於strtotime()

$timestamp = strtotime('2011-10-12 02:01:24'); 

echo 'The month is '.date('F', $timestamp).' and the day number is '.date('d', $timestamp); 

威爾輸出:

The month is October and the day number is 12

+0

這裏是我使用的代碼: $ date_of_post = $ r-> date_nw; \t \t \t $ month = MONTHNAME('$ date_of_post'); \t \t \t $ timestamp = strtotime('$ date_of_post'); \t \t \t echo'月份是'.date('F',$ timestamp)。'日期編號是'.date('d',$ timestamp); \t ($ R-> date_nw;),這是從數據庫中檢索日期和echo當它打印數據 致命錯誤:調用未定義的函數MONTHNAME()在E:\文件\本地機器(!) \ hi5tyle_ci \ application \ views \ inner_page.php 31行 – ahmedsaber111

+0

您混淆了MySQL和PHP的功能。簡單的方法就是按照你想要的來獲取MySQL的日期,然後在它上面應用PHP的strtotime()函數。 – Nicolas

相關問題