【问题标题】:php strtotime waring when convert date time in seconds [duplicate]以秒为单位转换日期时间时的php strtotime waring [重复]
【发布时间】:2014-01-15 07:45:39
【问题描述】:

我建立了生成报告的网站,我为此制作了一个 html 表单,并给出了两个字段的开始日期 时间和结束日期时间作为输入,并通过名称属性获取日期时间到另一个 php 页面 这里命名为report.php,我通过strtotime() 以秒为单位转换日期时间;并传入网址 在 url 我给 timezone=Asia/Calcutta.but 我收到了这样的警告信息-

警告:strtotime():依赖系统的时区设置是不安全的。您需要使用 date.timezone 设置或 date_default_timezone_set() 函数。如果您使用了这些方法中的任何一种,但仍然收到此警告,您很可能拼错了时区标识符。我们在第 232 行的 /var/www/html/vts/vehicalreport.php 中为 'MST/-7.0/no DST' 选择了 'America/Denver' 警告:strtotime():

我的 html 表单如下所示

    <!DOCTYPE html>
<html>
<head>

</head>
<body>
    <form  name ="reportform"  action="vehicalreport.php" method="get" rel="external" data-ajax="false">

         <label for="fromDate">Select From Date-Time</label>
             <input type="datetime-local" data-clear-btn="true" name="fromDate" id="fromDate" value="" required= "required" >
            <label for="toDate">Select To  Date-Time</label> 
              <input type="datetime-local" data-clear-btn="true" name="toDate" id="toDate" value="" required= "required" >

              <input id="view" type="submit" data-theme="b" value="View Report" rel="external">


        </form>
 </body>

   </html>

php 代码从 html 中获取日期时间,并在 strtotime 中放入一个传递 url

     $fromDate =$_GET["fromDate"];
     $toDate = $_GET["toDate"];
 $_SESSION['from']= strtotime($fromDate);
 $_SESSION['to']= strtotime($toDate);


     $data = array('a' =>$_SESSION['account'], '&u' =>$_SESSION['username'],'&p'
 =>$_SESSION['password'],'&d'=>$_SESSION['uniqueid'],'&tz'=> 'Asia/Calcutta','&rf'=>$_SESSION['from'],'&rt'=>$_SESSION['to'],'&limit'=>'10');
      echo curlUsingGet('http://"url":8080/events/data.json',$data);

【问题讨论】:

  • 这个问题似乎离题了,因为错误消息说明了发生了什么以及如何解决它。

标签: php html datetime


【解决方案1】:

在代码开头添加:

date_default_timezone_set('timezone');

您必须在此处获取您的时区:http://de3.php.net/manual/en/timezones.america.php

【讨论】:

    【解决方案2】:

    您需要在 php.ini 中设置服务器的 date.timezone 时区。

    根据您的系统设置,可以在不同的位置找到此文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-27
      • 2015-06-17
      • 2014-03-14
      • 1970-01-01
      • 2016-04-22
      • 1970-01-01
      • 2017-05-28
      • 1970-01-01
      相关资源
      最近更新 更多