【问题标题】:Not showing me the todays date没有显示今天的日期
【发布时间】:2013-09-21 19:42:25
【问题描述】:
<?php   
        for ( $i=1; $i<13; $i++ ) {
        $month = date('m', mktime(0,0,0,$i,2,2000));
        $sel = ( $i == date('n') ? ' selected="selected"' : '');
        $options1[] = "<option  value=\"{$month}\" {$sel}>{$month}</option>";
}
        $options_list1 = join("", $options1);
        echo "<select name=\"month\" >{$options_list1}</select>";

        for ( $j=1; $j<32; $j++ ) {
        $theday = date('d', mktime(0,0,0,0,$j,2000));
        $sel = ( $j == date('d') ? ' selected="selected"' : '');
        $options2[] = "<option  value=\"{$theday}\" {$sel}>{$theday}</option>";
}
        $options_list2 = join("\r\n", $options2);
        echo "<select name=\"day\" >{$options_list2}</select>";

      for ( $k=1960; $k<2016; $k++ ) {
      $theyear = date('Y', mktime(0,0,0,1,1,$k));
       $sel1 = ( $k == date("Y") ? ' selected="selected"' : '');
        $options3[] = "<option  value=\"{$theyear}\" {$sel1}>{$theyear}</option>";
}
        $options_list3 = join("\r\n", $options3);
        echo "<select name=\"year\" >{$options_list3}</select>";
        ?>

这是日期、月份和年份的下拉菜单。它显示今天的月份和年份,但在日期显示昨天的日期,例如今天的日期是 9/22/2013,它显示给我的日期是 9/21/2013。我做错了什么?

【问题讨论】:

  • PHP date returning wrong time 的可能重复项
  • 您遇到了时区问题。服务器/脚本时区与您的本地时区不同。查看echo date('Y-m-d H:i:s); 的输出并将其与您的本地时间进行比较。使用date_default_timezone_set() 设置时区。
  • @Glavić,我正在使用我的本地主机服务器,它显示我的系统日期
  • 如果echo date('d); 返回22 并且您仍在21 中,那么您有时区问题。如果它返回21,那么你没有问题,因为脚本应该可以工作。

标签: php date mktime


【解决方案1】:

您需要在php.ini 中使用date_default_timezone_set 设置您的时区

PHP Manual

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-12
    • 1970-01-01
    • 2012-10-22
    • 2018-12-07
    相关资源
    最近更新 更多