SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Handling date.timezone setting in an application

    Hi,

    There is one place in my application that I am using date() function. On servers where "date.timezone" is not set in the php.ini file, this function gives the following warning:

    Code:
    Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier.
    Now, since this application will be distributed and I can't control all servers, I am trying to find the best way to handle this.

    Here is the options I could find:

    1. Suppress the warning by "@date()".

    2. Check if "date.timezone" value is not set in php.ini and suppress the warning accordingly:

    Code:
    $timezone = ini_get('date.timezone');
    if (empty($timezone)) {
    echo @date('Y');
    } else {
    echo date('Y');
    }
    3. Check if "date.timezone" value is not set in php.ini and set a default timezone, which is not I want because the application will be used all around the world:

    Code:
    $timezone = ini_get('date.timezone');
    if (empty($timezone)) {
    date_default_timezone_set('Europe/London');
    }
    
    echo date('Y');
    Please let me know if you have any ideas about this. Thanks.

  2. #2
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    4,904
    Mentioned
    93 Post(s)
    Tagged
    0 Thread(s)
    I'd say go for option 3, what timezone is set to be used is down to whoever maintains a given server. You could have a note to whoever is installing the app just above or just below in a comment asking them to leave it set for GMT/UTC
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator


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
  •