1

The strftime() function in php is not showing the correct time on my system. I am running php on xampp. Its around 11 o'clock on my PC clock, but the function strftime() returns 19 when I execute the following code:-

echo 'Time is - '.strftime('%H');
vascowhite
  • 18,120
  • 9
  • 61
  • 77
Cooly Wizardy
  • 181
  • 2
  • 4
  • 7

3 Answers3

2

You can change your servers time zone by executing an ini_set at the top:

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

If you're on a hosting account the server is likely in a different time zone than you are. Even if you're running something locally I usually find it's set differently.

http://us3.php.net/timezones

Chords
  • 6,720
  • 2
  • 39
  • 61
0

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

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

take
  • 2,202
  • 2
  • 19
  • 36
0

You can also set your default timezone with running the following line on every request. You can achieve this easily if you put it in like a 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

Timezone names: http://www.php.net/manual/en/timezones.php

Ata S.
  • 890
  • 7
  • 12