Results 1 to 6 of 6

Thread: PHP Date and Timezones

  1. #1

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    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

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    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

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.)

  5. #5

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    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

  6. #6

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    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 );

    ?>
    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
  •  



Click Here to Expand Forum to Full Width