PHP TIME / DATE时区不起作用

时间:2017-01-03 08:17:16

标签: php date time

我试着回复日期,但是日期是提前一小时,我已经改变了ini中的时区,但它不起作用。

那是我的代码:

$year = date('y');
$month = date('m');
$day = date('d');
$hour = date('H');
$min = date('i');
$sek = date('s');
$date = $day . "." . $month . "." . $year . "/" . $hour . ":" . $min .    ":" . $sek;
echo $date;

提前致谢!

现在我有9:34,但网站显示我8:34 重新启动后它不起作用!

4 个答案:

答案 0 :(得分:1)

此代码将为您提供不同大洲的日期和调整。 Code Woks

<?php
date_default_timezone_set("Asia/Calcutta");
echo "The Date in Calcutta India is " . date("d-m-y");
echo "<br>The Time in Calcutta India is" . date("h-i-s-a");

date_default_timezone_set("America/New_York");
echo "<br><br>The Date in New York America is " . date("d-m-y");
echo "<br>The Time in New York America  is " . date("h-i-s-a");
?>

答案 1 :(得分:0)

您可以设置时区:

// date_default_timezone_set('CET');
date_default_timezone_set('Continent/Country');
$year = date('y');
$month = date('m');
$day = date('d');
$hour = date('H');
$min = date('i');
$sek = date('s');
$date = $day . "." . $month . "." . $year . "/" . $hour . ":" . $min .    ":" . $sek;
echo $date;

答案 2 :(得分:0)

您需要设置默认时区。

Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/jiangyahui/worksp/php/test_1.php on line 8

03.01.17/08:21:18

答案 3 :(得分:0)

您确定您设置的时区有效吗? 您可以回显phpinfo();并查看“date.timezone”字段。如果值不正确,您可以在代码中使用date_default_timezone_set('YOUR TIMEZONE');更改时区

注意:如果您想以格式打印日期时间,可以使用

date("y.m.d/H:i:s");