|
-
Jan 2nd, 2008, 12:58 AM
#1
Thread Starter
WiggleWiggle
PHP Date and Timezones
Is there an easy way to make the date function work with the viewer's timezone without having to use mktime?
i know that at some point the user is going to need to give their timezone, but is there a php function that will automatically change it for that session?
My usual boring signature: Something
-
Jan 2nd, 2008, 05:53 AM
#2
Re: PHP Date and Timezones
-
Aug 3rd, 2008, 11:22 PM
#3
Thread Starter
WiggleWiggle
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?
My usual boring signature: Something
-
Aug 8th, 2008, 10:50 PM
#4
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.)
-
Aug 8th, 2008, 11:05 PM
#5
Thread Starter
WiggleWiggle
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...
My usual boring signature: Something
-
Aug 8th, 2008, 11:07 PM
#6
Thread Starter
WiggleWiggle
Re: PHP Date and Timezones
hmm found this. will try it.
 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 );
?>
My usual boring signature: Something
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|