在PHP中,您可以:
有点像这样,我会说:
$timestamp = strtotime($date_from_db);
echo date('d/m/Y', $timestamp);
但这仅适用于1970年至2038年之间的日期,因为时间戳存储为32位整数,从1970-01-01开始计数。
在MysqL中,我想date_format
函数可以解决问题。 例如 :
MysqL> select date_format(curdate(), '%d/%m/%Y');
+------------------------------------+
| date_format(curdate(), '%d/%m/%Y') |
+------------------------------------+
| 19/03/2010 |
+------------------------------------+
1 row in set (0.03 sec)
而且,为了完善起见,PHP中的另一种不受1970-2038年限制的解决方案是使用DateTime
该类,尤其是:
例如,这部分代码:
$date = new DateTime('2010-03-19');
echo $date->format('d/m/Y');
会给你这个输出:
19/03/2010