I have unix timestamps created in a database table. I know user's timezone it is also saved in a table and int the format of "GMT+04:00" , "GMT+05:30"
What I'm trying to do is take the timestamp and show readable time to the users according to their timezone.
Ex.
$startTime = '1524391500';
echo date('h:ia', $startTime) . '<br>';
date_default_timezone_set('America/Fortaleza');
echo date('h:ia', $startTime) . '<br>';
this will give us the result
10:05am
07:05am
The problem is date_default_timezone_set doesn't accept the timezone in this
date_default_timezone_set('GMT+05:30');
So I need a way to convert "GMT+05:30" to something like "America/Fortaleza"
can some one help me with this?
What you ask for is not possible. A time zone and a time zone offset are two different things.
Consider a single time zone like America/Sao_Paulo
. It uses an offset of -03:00
during Standard Time, and an offset of -02:00
during Daylight Saving Time.
Now consider that America/Fortaleza
you mentioned uses -03:00
over the entire year.
As you can see, for a given time zone I may have more than one offset, and for a given offset I may have more than one time zone. You can review the lists of time zones and their offsets if you want to find more examples for yourself.
This is covered extensively in other answers, as well as in the "Time Zone != Offset" section of the timezone tag wiki.