Results 1 to 6 of 6

Thread: Adjusting timezones

  1. #1
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default Adjusting timezones

    I'm trying to compare the current time with one from another (SVN) server, set in GMT and formatted as 'D, d M Y H:i:s e', but I'm having problems getting a GMT/UTC timestamp from the supplied date-string. Unfortunately my deployment server is running PHP 5.1.6, so I can't take advantage of DateTime::getTimestamp which would work perfectly for this. So I've pieced together a solution which I think should be portable across PHP 5.1+ installations but would appreciate feedback from anyone interested in giving it. (I started typing this as a question, but I'm not totally confident about the answer I formulated.)

    Here's the code, where $dateString is the date retrieved from the other server.
    Code:
    $dateTime = new DateTime($dateString);
    $timezone = new DateTimeZone(date_default_timezone_get());
    $offset = timezone_offset_get($timezone, $dateTime);
    $timestamp = strtotime($dateString) - $offset;
    echo $dateString . '<br />' . PHP_EOL;/* These should be identical, except the timezone which my PHP insists on showing as "System/Localtime" below. */
    echo date('D, d M Y H:i:s e', $timestamp) . '<br />' . PHP_EOL;
    echo $timestamp . '<br />' . PHP_EOL;
    Thanks for any input.
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Maybe:

    http://www.php.net/manual/en/reserve...les.server.php

    Scroll down that page to:

    'REQUEST_TIME'
    The timestamp of the start of the request. Available since PHP 5.1.0.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    Err, I guess I should have stated my problem at the first of that first sentence:
    I'm having problems getting a GMT/UTC timestamp from the supplied date-string.
    (For that matter, now that I have re-read my post I notice that the current time is not relevant to the issue at all. The time to be compared with that from the server is when a local file was last modified, but neither is that directly relevant to this question.)
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  4. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Corrections to my coding/thoughts welcome.

  5. #5
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    *facepalm* Sorry, no offense - I just can't believe you both got sidetracked by the "local filesystem" portion of this feature. I apparently explained my problem very poorly so I'll try again, with more background info this time. I left it out because normally I consider it fluff but I think it clears some things up in this case.

    I'm developing the Kuva project and recently adopted its inactive dependency phpsvnclient. I'm trying to make Kuva able to update all of a site's components via SVN, hence the dependency. phpsvnclient supplies the paths of its source tree along with a last-modified date. I want to convert that date into a timestamp on my server; I cannot access the files on the Google Code server to manually find this timestamp. The code I supplied above is my (hypothetical) solution for converting to the timestamp from which I can subtract the local last-modified (returned from filemtime).
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  6. #6
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    (bumpety) Is there really no cleaner way to convert a date-string to a timestamp?
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

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
  •