SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict Percipient's Avatar
    Join Date
    Jun 2000
    Location
    Summerland, BC, Canada.
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How would I convert the time PHP gets from my server to another time zone, such as my own? I figure just subtracting 3 hours from the date() output could lead to erroneous results if it's only 2 o'clock.
    Ed Rands

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to use mktime and in your mktime call you can subtract the hours for instance let's say your server is 3 hours ahead of your local time.

    PHP Code:
    $localdate date("m-d-Y g:i:s"mktime(date("G") - 3date("i"),date("s"),date("m"), date("d"), date("Y"))); 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Addict Percipient's Avatar
    Join Date
    Jun 2000
    Location
    Summerland, BC, Canada.
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And then if I wanted to disregard Daylight Savings Time, I'd do something like this, for a time zone 3 hours ahead of my server...

    PHP Code:
    if (date("I")) {
     
    $date_time date("D, M jS, Y g:i a"mktime(date("G") +2date("i"),date("s"),date("m"), date("d"), date("Y")));
    } else {
     
    $date_time date("D, M jS, Y g:i a"mktime(date("G") +3date("i"),date("s"),date("m"), date("d"), date("Y")));
    }
    echo 
    "$date_time VRT"
    Right?
    Last edited by Percipient; Mar 13, 2001 at 12:48.
    Ed Rands

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah or using the ternorary(sp?) operator
    PHP Code:
    $numhrs = (date("I")) ? 3;
    $date_time date("D, M jS, Y g:i a"mktime(date("G") + $numhrsdate("i"),date("s"),date("m"), date("d"), date("Y")));
    echo 
    "$date_time VRT"
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Addict Percipient's Avatar
    Join Date
    Jun 2000
    Location
    Summerland, BC, Canada.
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, that takes up less space.

    (Groans.) I'm going to have to get a lot better than this. Takes me an hour just to code the display of a date. Okay, so it takes one minute to display *a* date, but an hour to code *the* date and time I want. But, it should be a lot quicker next time, with this under my hat.
    Ed Rands


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
  •