Need a help: Change a date & time to other in DST difference

Discussion in 'PHP' started by lovelycesar, Aug 23, 2008.

  1. #1
    I want to write a function like to do the following:
    - I have a date & time like: 23-Aug-2008 23:10 GMT-0400
    - I want to display it as : 24-Aug-2008 04:10 GMT+0100
    Can you help me to do it? (for PHP4 & PHP5)
    Thanks.
     
    lovelycesar, Aug 23, 2008 IP
  2. lp1051

    lp1051 Well-Known Member

    Messages:
    163
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #2
    From PHP 5.1, you can change default timezone either in .INI or with function date_default_timezone_set() to the zone that has GMT +001 (else taken from server time), so you will get the time you need.
    And earlier versions should support this workaround : date("d-M-Y H:i:s \G\M\T +001",strtotime("+5 hours")), but it's not so dynamic, as soon as you or your hosting change server location/timezone...
     
    lp1051, Aug 23, 2008 IP
  3. lovelycesar

    lovelycesar Peon

    Messages:
    145
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks, I know it in PHP 5, but if we set the default time zone, we make all user's time zones be identical. My purpose is each user has each time zone.
     
    lovelycesar, Aug 23, 2008 IP
  4. lovelycesar

    lovelycesar Peon

    Messages:
    145
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Can anyone help me more?
     
    lovelycesar, Aug 27, 2008 IP
  5. lp1051

    lp1051 Well-Known Member

    Messages:
    163
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #5
    What more would you need?? Either you're interested in changing the date format for everybody (no matter where they are), or if you want to accept user's time zones, let them choose when they register or somewhere. You have the same feature here on DP. Then you just fetch the timezone identifier and use it like e.g. putenv("TZ=US/Eastern"); for that user.
    Is it better??
     
    lp1051, Sep 1, 2008 IP
  6. smbasha

    smbasha Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    you can use date_format() function but it is working in 5.2.6 .
     
    smbasha, Sep 1, 2008 IP
  7. lovelycesar

    lovelycesar Peon

    Messages:
    145
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    If a user has chosen its time displayed as: 23 Aug 2008 23:12:00 +0400
    If other user has its time displayed as: 23 Aug 2008 23:12:00 +0200
    If other user has its time displayed as: 23 Aug 2008 23:12:00 -0400

    All time recorded in database in unique DST : 23 Aug 2008 23:12:00 -0400

    How the system will display for each user above?
     
    lovelycesar, Sep 2, 2008 IP