我正在尝试将 DATETIME 格式化为西类牙语,这样它就不会显示为“2015-11-14 13:22:33”。
实际上我是在这样的查询上调用我的日期时间
$not_Fecha = $rows_result ['nw_Fecha'];
并在此处设置格式(dias = 天,meses = 月):
<?php $not_Fecha = new DateTime($result->my_datetime);
$dias = array("Domingo","Lunes","Martes","Miercoles","Jueves","Viernes","Sábado");
$meses = array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
echo $result = $dias[date('w')]." ".date('d')." de ".$meses[date('n')-1]. " del ".date('Y'). " a las ".date('g:i A') ;
?>
但它显示的是今天的日期,而不是我数据库中存储的日期。会是什么?
最佳答案
您永远不会使用数据库中的日期。您只使用今天使用的 date()
(除非您给它一个不同日期的 Unix 时间戳)。将您对日期的调用替换为使用代表您要使用的实际日期的 DateTime
对象。
<?php
$not_Fecha = new DateTime($result->my_datetime);
$dias = array("Domingo","Lunes","Martes","Miercoles","Jueves","Viernes","Sábado");
$meses = array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
echo $result = $dias[$not_Fecha->format('w')]." ".$not_Fecha->format('d')." de ".$meses[$not_Fecha->format('n')-1]. " del ".$not_Fecha->format('Y'). " a las ".$not_Fecha->format('g:i A') ;
?>
关于php - 在 PHP 中格式化 MySQL 日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33725823/