Strftime () function shows wrong time

The strftime() function in php does not show the correct time on my system. I am running php on xampp. Its about 11 hours on my pc's clock, but the strftime() function returns 19 when I execute the following code: -

 echo 'Time is - '.strftime('%H'); 
+1
function php
source share
3 answers

You can change the time zone of your servers by doing ini_set at the top:

ini_set( 'date.timezone', 'Europe/Berlin' );

If you are using a hosting account, the server is most likely in a different time zone than you. Even if you run something locally, I usually install it differently.

http://us3.php.net/timezones

+2
source share

Perhaps the wrong time zone is set in php.ini: http://www.dedyisn.net/linux/how-to-setting-default-time-zone-in-apache-webserver-for-php/

date ("H"); also gives the wrong time?

0
source share

You can also set the default time zone by running the following line for each query. You can easily achieve this by placing it in the config.php or header.php file of your project.

 date_default_timezone_set ( string $timezone_identifier ) 

Source: http://php.net/manual/en/function.date-default-timezone-set.php

Time Zone Names: http://www.php.net/manual/en/timezones.php

0
source share

All Articles