0

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.

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 !

c.Bauer
  • 52
  • 11

4 Answers4

1

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");
?>
Pavan Baddi
  • 479
  • 1
  • 11
  • 22
0

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;
Peter Krauss
  • 13,174
  • 24
  • 167
  • 304
Michael
  • 405
  • 4
  • 10
0

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
YaHui Jiang
  • 130
  • 6
0

Are you sure about the timezone you set it work? you can echo phpinfo(); and check "date.timezone" field. if the value is not right you can use 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");
goto
  • 7,908
  • 10
  • 48
  • 58