在时区显示当前时间时出现问题

时间:2014-09-26 08:52:03

标签: php html

如果我添加

,有人可以解释为什么页面停止工作
<?php
date_default_timezone_set("$tidszon");
echo "Klockan &auml;r " . date("h:i:sa")" i tidszonen du angav.";
?>

到代码的显示输入部分?其他一切正常,但如果我添加该页面甚至不加载..

这是未添加时区的默认代码:                           

<?php
// define variables and set to empty values
$y1 = $m1 = $d1= $y2 = $m2 = $d2=  $tidszon = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
   $y1 = test_input($_POST["y1"]);
   $m1 = test_input($_POST["m1"]);
   $d1 = test_input($_POST["d1"]);
   $y2 = test_input($_POST["y2"]);
   $m2 = test_input($_POST["m2"]);
   $d2 = test_input($_POST["d2"]);   
   $tidszon = test_input($_POST["tidszon"]);
}

function test_input($data) {
   $data = trim($data);
   $data = stripslashes($data);
   $data = htmlspecialchars($data);
   return $data;
}
?>

<h2>Lookup how many days between which dates?</h2> 
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> 
   <br><br>
       Date 1:
       <br>
    <select name="y1" size="4">
    <option value="2001">2001</option>
    <option value="2002">2002</option>
    <option value="2003">2003</option>
    <option value="2004">2004</option>
    <option value="2005">2005</option>
    <option value="2006">2006</option>
    <option value="2007">2007</option>
    <option value="2008">2008</option>
    <option value="2009">2009</option>
    <option value="2010">2010</option>
    <option value="2011">2011</option>
    <option value="2012">2012</option>
    <option value="2013">2013</option>
    <option value="2014">2014</option>
    </select>
    <select name="m1" size="4">
    <option value="1">January</option>
    <option value="2">February</option>
    <option value="3">Mars</option>
    <option value="4">April</option>
    <option value="5">May</option>
    <option value="2006">June</option>
    <option value="2007">July</option>
    <option value="2008">August</option>
    <option value="2009">September</option>
    <option value="2010">October</option>
    <option value="2011">November</option>
    <option value="2012">December</option>
    </select>
    <select name="d1" size="4">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    <option value="9">9</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
    <option value="13">13</option>
    <option value="14">14</option>
    <option value="15">15</option>
    <option value="16">16</option>
    <option value="17">17</option>
    <option value="18">18</option>
    <option value="19">19</option>
    <option value="20">20</option>
    <option value="21">21</option>
    <option value="22">22</option>
    <option value="23">23</option>
    <option value="24">24</option>
    <option value="25">25</option>
    <option value="26">26</option>
    <option value="27">27</option>
    <option value="28">28</option>
    <option value="29">29</option>
    <option value="30">30</option>
    <option value="31">31</option>
    </select>
    <br>
    <br>
    Date 2:
    <br>
    <select name="y2" size="4">
    <option value="2001">2001</option>
    <option value="2002">2002</option>
    <option value="2003">2003</option>
    <option value="2004">2004</option>
    <option value="2005">2005</option>
    <option value="2006">2006</option>
    <option value="2007">2007</option>
    <option value="2008">2008</option>
    <option value="2009">2009</option>
    <option value="2010">2010</option>
    <option value="2011">2011</option>
    <option value="2012">2012</option>
    <option value="2013">2013</option>
    <option value="2014">2014</option>
    </select>
    <select name="m2" size="4">
    <option value="1">January</option>
    <option value="2">February</option>
    <option value="3">Mars</option>
    <option value="4">April</option>
    <option value="5">May</option>
    <option value="2006">June</option>
    <option value="2007">July</option>
    <option value="2008">August</option>
    <option value="2009">September</option>
    <option value="2010">October</option>
    <option value="2011">November</option>
    <option value="2012">December</option>
    </select>
    <select name="d2" size="4">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    <option value="9">9</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
    <option value="13">13</option>
    <option value="14">14</option>
    <option value="15">15</option>
    <option value="16">16</option>
    <option value="17">17</option>
    <option value="18">18</option>
    <option value="19">19</option>
    <option value="20">20</option>
    <option value="21">21</option>
    <option value="22">22</option>
    <option value="23">23</option>
    <option value="24">24</option>
    <option value="25">25</option>
    <option value="26">26</option>
    <option value="27">27</option>
    <option value="28">28</option>
    <option value="29">29</option>
    <option value="30">30</option>
    <option value="31">31</option>
    </select>
   <br><br>
   Timezone:<input type="text" name="tidszon">
   <br><br>
   <input type="submit" name="submit" value="Submit"> 
</form>

<?php
echo "<h2>Your Input:</h2>";
echo "<br>"; 
echo "<br>"; 
echo "Date 1: ";
echo $y1;
echo "/";
echo $m1;
echo "/";
echo $d1;
echo "<br>";
echo "Date 2: ";
echo $y2;
echo "/";
echo $m2;
echo "/";
echo $d2;
echo "<br>";   
echo "<br>";
echo "Timezone: ";
echo $tidszon;
echo "<br>";
echo "<br>";
echo "<br>";
?>
<br>

<br>
<?php
require_once 'Date.php';
try {
    // create two Pos_Date objects new
    $dat1 = new Pos_Date();
    $dat2 = new Pos_Date();
    // calculate the number of days
        $dat1->setDate($y1,$m1,$d1);
        $dat2->setDate($y2,$m2,$d2);
    $diff = Pos_Date::dateDiff($dat1, $dat2);
    $unit = abs($diff) > 1 ? 'days' : 'day'; 
        echo "There is " . abs($diff) . " $unit between the dates";
} catch (Exception $e) {
    echo $e;
}
?>

</body>
</html>

2 个答案:

答案 0 :(得分:0)

删除日期(“h:i:sa”)而不是使用

<?php
date_default_timezone_set("$tidszon");
echo "Klockan &auml;r " . date("h:i:sa")." i tidszonen du angav.";
?>

答案 1 :(得分:0)

.后发现date()echo "Klockan &auml;r " . date("h:i:sa") . " i tidszonen du angav."

提交错误报告,以便将来获得有关拼写错误和其他错误的信息性消息。

并在旁注。如果您可以使用例如utf-8编码而不是html实体,那么您和其他所有人都可以更轻松地阅读源代码。