Re: PHP Date and Timezones
Re: PHP Date and Timezones
coming back to this, would setting a time zone plus/minus for each user in the database, then adding/subtracting that time from the unix epoch using date() to format it?
Re: PHP Date and Timezones
Yes, but why not use the built-in timezone functionality?
(There are even some classes in PHP 5.2 that wrap dates and times, although they didn't work properly the last time I tried.)
Re: PHP Date and Timezones
i think i am making a complicated thing out of a simple thing.
I want to have my users select their timezone, should i include all of them, or just some of them..
something that just came to mind is when they are selecing them, they should start typing the name of their city, and i could do like a suggested search type thing...
Re: PHP Date and Timezones
hmm found this. will try it.
Quote:
Originally Posted by PHP.net
If you want users to choose their own timezones, here's some code that gets all available timezones but only uses one city for each possible value:
PHP Code:
<?php
$timezones = DateTimeZone::listAbbreviations();
$cities = array();
foreach( $timezones as $key => $zones )
{
foreach( $zones as $id => $zone )
{
/**
* Only get timezones explicitely not part of "Others".
* @see http://www.php.net/manual/en/timezones.others.php
*/
if ( preg_match( '/^(America|Antartica|Arctic|Asia|Atlantic|Europe|Indian|Pacific)\//', $zone['timezone_id'] ) )
$cities[$zone['timezone_id']][] = $key;
}
}
// For each city, have a comma separated list of all possible timezones for that city.
foreach( $cities as $key => $value )
$cities[$key] = join( ', ', $value);
// Only keep one city (the first and also most important) for each set of possibilities.
$cities = array_unique( $cities );
// Sort by area/city name.
ksort( $cities );
?>