I want to show date in local time zone but i have saved date in UTC, there is any to show it in local time zone using php.
Asked
Active
Viewed 522 times
0
-
Duplicate of http://stackoverflow.com/questions/2548235/convert-utc-datetime-to-another-time-zone – Liath Jan 15 '14 at 08:30
-
i want to do this in php. Is it posible in php ? – Pushpendra Singh Jan 15 '14 at 09:07
-
I've retagged your question so the php guys will see it. I would advise you spend some time expanding it yourself http://stackoverflow.com/questions/how-to-ask – Liath Jan 15 '14 at 09:10
-
http://stackoverflow.com/questions/3792066/convert-utc-dates-to-local-time-in-php have you searched about this ?? – Kaushik Jan 15 '14 at 09:23
1 Answers
0
PHP's strtotime
function will interpret timezone codes, like UTC. If you get the date from the database/client without the timezone code, but know it's UTC, then you can append it.
Assuming you get the date with timestamp code (like "Fri Mar 23 2012 22:23:03 GMT-0700 (PDT)", which is what Javascript code ""+(new Date())
gives):
$time = strtotime($dateWithTimeZone);
$dateInLocal = date("Y-m-d H:i:s", $time);
Or if you don't, which is likely from MySQL, then:
$time = strtotime($dateInUTC.' UTC');
$dateInLocal = date("Y-m-d H:i:s", $time);
Alternatively
date()
and localtime()
both use the local timezone for the server unless overridden; you can override the timezone used with date_default_timezone_set()
.
you may find these links useful

Kaushik
- 2,072
- 1
- 23
- 31