简体   繁体   English

PHP TIME / DATE时区不起作用

[英]PHP TIME/DATE timezone dont work

i try to echo the date but the date is one hour to early, i already changed the timezone in the ini but it doesnt work. 我尝试回显日期,但日期早了一个小时,我已经更改了ini中的时区,但它不起作用。

thats my code: 那就是我的代码:

$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;

Thanks in advance! 提前致谢!

Now i have 9:34 but the site shows me 8:34 after restart it doesnt work ! 现在我有9:34,但是该站点在重启后向我显示8:34,它不起作用!

This code will get you the date and timming of differen continents. 此代码将为您提供不同大洲的日期和时间。 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");
?>

You can set your timezone: 您可以设置时区:

// 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;

you need setting default timezone。 您需要设置默认时区。

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

Are you sure about the timezone you set it work? 您确定将其设置为工作的时区吗? you can echo phpinfo(); 您可以回显phpinfo(); and check " date.timezone " field. 并检查“ date.timezone ”字段。 if the value is not right you can use date_default_timezone_set('YOUR TIMEZONE'); 如果该值不正确,则可以使用date_default_timezone_set('YOUR TIMEZONE'); for change timezone in your code 在代码中更改时区

Note: if you want to print date time in your format you can use 注意:如果要以格式打印日期时间,可以使用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM