SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    531
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting the Timezone

    we're stuck with PHP 4 and i'm needing to obtain the timezone from the unix box.

    i try getenv('TZ') but it always comes up empty.

    is there another way to read the timezone from the unix box?

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    date()

    Although, php may not neccesarily be set to the same timezone as the OS.

  3. #3
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Some of the PHP date options might be available to PHP4, just run them and see if they work.

    PHP Code:
    php -"echo date('e * O * T * Z') . \"\n\";"
    America/Denver * -0700 MST * -25200 
    If I may ask, how exactly do you become stuck with PHP4? Version 5 has been stable for around 5 years now.
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  4. #4
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    531
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's just what we have on our production units and it's not up to me to decide what version we have installed and we're stuck with it.

    unfortunately the 'e' in date() is a 5+ addition. :/ that would be great for what i need.

    any idea why when i call upon getenv('TZ') it doesn't return the correct timezone?

    it SHOULD be pulling in America/New_York.

  5. #5
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whoops, I forgot "e" is PHP5, did you try the others though? O T and Z?
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  6. #6
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    531
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    they want the list that the user chooses from to have the countries' (as seen when using 'e') names in them.

    not sure the best way around it.

  7. #7
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    531
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sooooo... anyone have any idea why getenv('TZ') doesn't work just how date('e') in PHP 5 does?

    i can only get getenv('TZ') to work after i've set TZ, which sucks.

  8. #8
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If your boss isn't the one actually coding the software on your production server, then he also probably won't know that PHP should be updated unless you tell him.

    You could make an incredibly strong case to bring to him. It's probably costing your company money for you to be screwing around with PHP4 when your productivity could be so much higher with PHP5. And all for what... not typing `yum update php`?

    There's no excuse for any applications in active development to still be using PHP4, none at all. This is something you should definitely talk to him about.

    If not, then you're going to need to maintain a database of timezones and read from that. The built in timezone extension is built from a list acquired here: ftp://elsie.nci.nih.gov/pub/

    Edit:

    An alternative might be using a different format for your drop down menu.

    I've seen sites use something like:

    What time is it now?
    ===============
    ...
    11:15 AM
    12:15 PM
    1:15 PM
    2:15 PM
    ...

    With success
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  9. #9
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    531
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i'm just going to run this unix command. it actually pulls the info i need.

    ls -l /etc/localtime

  10. #10
    SitePoint Evangelist simshaun's Avatar
    Join Date
    Apr 2008
    Location
    North Carolina
    Posts
    438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try
    PHP Code:
    echo var_dump(getenv('TZ')); 
    and see if it displays FALSE.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •