doukong6031 2014-05-26 15:05
浏览 26
已采纳

存储在变量上的日期和时间不会在页面时刷新

Date and time are setted to Madrid's standard UTC, and stored for translation and formatting in this way:

date_default_timezone_set('Europe/Madrid');
$dia=""; $mes=""; $dia2=""; $ano=""; $horaActual=""; $minutoActual="";

        $dia=date("l");
        if ($dia=="Monday") {$dia="Lunes";}         if ($dia=="Tuesday") {$dia="Martes";}        if ($dia=="Wednesday") {$dia="Miércoles";}        if ($dia=="Thursday") {$dia="Jueves";}        if ($dia=="Friday") {$dia="Viernes";}        if ($dia=="Saturday") {$dia="Sabado";}        if ($dia=="Sunday") {$dia="Domingo";}

        $mes=date("F");
        if ($mes=="January") {$mes="Enero";}        if ($mes=="February") {$mes="Febrero";}        if ($mes=="March") {$mes="Marzo";}        if ($mes=="April") {$mes="Abril";}        if ($mes=="May") {$mes="Mayo";}        if ($mes=="June") {$mes="Junio";}        if ($mes=="July") {$mes="Julio";}        if ($mes=="August") {$mes="Agosto";}       if ($mes=="September") {$mes="Setiembre";}        if ($mes=="October") {$mes="Octubre";}        if ($mes=="November") {$mes="Noviembre";}        if ($mes=="December") {$mes="Diciembre";}

        $dia2=date("d"); 
        $ano=date("Y");
        $horaActual=date("H");
        $minutoActual=date("m");

This gives the same time and date all the time (I created this an hour ago), not refreshing while web browser does. In this right moment, this code:

<?php echo  "$dia $dia2 de $mes, $horaActual:$minutoActual"; echo "--" date("F j, Y, g:i a");?>

Shows:

Lunes 26 de Mayo, 16:05 -- May 26, 2014, 5:03 pm

So date() is getting the correct and updated info, but variables are not updating this info, showing stucked data from the first time they stored this values.

every time user gets inside this url, date and time must be updated with actual values

  • 写回答

1条回答 默认 最新

  • duankanjian4642 2014-05-26 15:23
    关注

    I dont know how your time got stuck, but alternatively you could do this (time updated). Consider this example:

    date_default_timezone_set('Europe/Madrid');
    $dia = $mes = $dia2 = $ano = $horaActual = $minutoActual = "";
    $days = array('Monday' => 'Lunes', 'Tuesday' => 'Martes', 'Wednesday' => 'Miércoles', 'Thursday' => 'Jueves', 'Friday' => 'Viernes', 'Saturday' => 'Sabado', 'Sunday' => 'Domingo');
    $months = array('January' => 'Enero', 'February' => 'Febrero', 'March' => 'Marzo', 'April' => 'Abril', 'May' => 'Mayo', 'June' => 'Junio', 'July' => 'Julio', 'August' => 'Agosto', 'September' => 'Setiembre', 'October' => 'Octube', 'November' => 'Noviembre', 'December' => 'Diciembre');
    
    $dia = date("l");
    $mes = date("F");
    $dia2 = date("d"); 
    $ano = date("Y");
    // $horaActual = date("H");
    // $minutoActual = date("m");
    $time = date('H:i');
    
    echo  "$days[$dia] $dia2 de $months[$mes], $time"; echo "--". date("F j, Y, g:i a");
    // outputs: Lunes 26 de Mayo, 17:21--May 26, 2014, 5:21 pm
    

    Fiddle

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题