我得到的數據從數據庫到HTML頁面日期轉換到PHP
<?php $subscriber = json_decode($this->subscriber); ?>
我顯示的所有元素作爲
<?php echo $subscriber->date; ?>
哪裏像現在我要顯示的日期。當我直接顯示日期時我得到的格式爲2014-07-15 17:02:50
但我想顯示格式15-07-2014。使用哪些函數以及如何在PHP中編寫代碼?
我得到的數據從數據庫到HTML頁面日期轉換到PHP
<?php $subscriber = json_decode($this->subscriber); ?>
我顯示的所有元素作爲
<?php echo $subscriber->date; ?>
哪裏像現在我要顯示的日期。當我直接顯示日期時我得到的格式爲2014-07-15 17:02:50
但我想顯示格式15-07-2014。使用哪些函數以及如何在PHP中編寫代碼?
使用PHP的DateTime
類做的面向對象的方法:
$dt = new DateTime($subscriber->date);
echo $dt->format('d-m-Y');
或者你也可以從字符串首先轉換日期使用strtotime()
Unix時間戳然後用date()
函數格式化爲Vijayaragavendran,他在回答中提到:
echo date('d-m-Y',strtotime($subscriber->date));
使用日期()函數
date('d-m-y',strtotime($subscriber->date))
Lol看起來像你在你的更新中做了類似的錯字...'y' :) –
哈哈是的,修復它。 – TiMESPLiNTER