I am using the following PHP code to get the current time.
$time = time();
echo date('h:m:s A',$time);
The time returned is the wrong time. The current time is 05:14:33
PM on my computer and this function is showing 12:03:02
PM.
Why it is giving the wrong time and how can I get PHP to give the right time?
time()
gives the number of seconds since 1 Jan 1970 UTC. This is read from the internal clock in your OS/computer. date()
gives you the date on a timestamp in the default timezone.
Use date_default_timezone_set
and date_default_timezone_get
to check/set the correct timezone.
Alternatively you can set the default timezone in your php.ini
Please set your timezone if you have errors on your current time. Here you can find more information about it ... http://www.php.net/manual/en/function.date-default-timezone-set.php
Here you can find all timezones: http://www.php.net/manual/en/timezones.php