I'm storing the UTC dates into the DB using:
$utc = gmdate("M d Y h:i:s A");
and then I want to convert the saved UTC date to the client's local time.
How can I do that?
Thanks
I'm storing the UTC dates into the DB using:
$utc = gmdate("M d Y h:i:s A");
and then I want to convert the saved UTC date to the client's local time.
How can I do that?
Thanks
Given a local timezone, such as 'America/Denver', you can use DateTime class to convert UTC timestamp to the local date:
Date arithmetic is not needed if you just want to display the same timestamp in different timezones:
I store date in the DB in UTC format but then I show them to the final user in their local timezone
Answer
Convert the UTC datetime to America/Denver
Notes
time()
returns the unix timestamp, which is a number, it has no timezone.date('Y-m-d H:i:s T')
returns the date in the current locale timezone.gmdate('Y-m-d H:i:s T')
returns the date in UTCdate_default_timezone_set()
changes the current locale timezoneto change a time in a timezone
here you can see all the available timezones
https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
here are all the formatting options
http://php.net/manual/en/function.date.php
Update PHP timezone DB (in linux)