SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard wdmny's Avatar
    Join Date
    Jul 2000
    Location
    Here
    Posts
    1,010
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Time Zone Help (GMT Offset?)

    I have run into a bit of a time zone problem. Basically, I am using ASP and Javascript to handle dates and guess what... you got it, the client could be in any time zone but the server will always be in the same one (UK actually).

    I have figured the best method would be to use Javascript to determine the GMT offset (.getTimeZoneOffset), then pass that to my ASP script (I am already doing Javascript->ASP work, I am just appending this to the end of the querystring). ASP will have two dates then, the server date and the client date, and then the client GMT offset.

    Once I get this offset in ASP, how can I use that with the dates/times I am working with?

    Thanks,

  2. #2
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Well, what are you using the times/dates for? I mean, what do you need a correct server time for, what do you need the correct client time for?
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  3. #3
    SitePoint Wizard wdmny's Avatar
    Join Date
    Jul 2000
    Location
    Here
    Posts
    1,010
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am comparing the dates. Javascript will keep "hitting" this ASP file with a date. This date will be compared with a date called out of the database. All this code works fine and well. The problem is that the ASP date and the Javascript date are roughly an hour off (the times between when they are each retrieved add a few seconds), even when they were pulled just seconds apart.

    I know it is the timezones, I tried to leave out all the other stuff because I have already debugged it and it would just add a whole lot of confusion.

    Edit: I have considered other alternatives and this is the best way. Sure I could just add or subtact an hour, but then I would have unportable code.

  4. #4
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Here's some basic JS timecode...

    Code:
    <script LANGUAGE="JavaScript">
    <!-- Original:  Emanuel Gavrilv (eltal@sprint.ca) -->
    <!-- Web Site:  http://www.angelfire.com/on/eltal -->
    <!-- Begin
    
    function GetTime() { 
    var dt = new Date();
    var def = dt.getTimezoneOffset()/60;
    var gmt = (dt.getHours() + def);
    document.clock.local.value = (IfZero(dt.getHours()) + ":" + IfZero(dt.getMinutes()) + ":" + IfZero(dt.getSeconds()));
    var ending = ":" + IfZero(dt.getMinutes()) + ":" +  IfZero(dt.getSeconds());
    var _GMT =check24(((gmt) > 24) ? ((gmt) - 24) : (gmt));
    document.clock._GMT.value = (IfZero(_GMT) + ":" + IfZero(dt.getMinutes()) + ":" + IfZero(dt.getSeconds()));
    
    // To adjust for new daylight savings time, change all 24-4 to 24-5
    var east =check24(((gmt + (24-4)) > 24) ? ((gmt + (24-4)) - 24) : (gmt + (24-4)));
    document.clock.east.value = (IfZero(east) + ending);
    setTimeout("GetTime()", 1000);
    }
    
    function IfZero(num) {
    return ((num <= 9) ? ("0" + num) : num);
    }
    
    function check24(hour) {
    return (hour >= 24) ? hour - 24 : hour;
    }
    //  End -->
    </script>
    Dunno... You could modify it a little to make it ping out the client time.
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  5. #5
    SitePoint Wizard wdmny's Avatar
    Join Date
    Jul 2000
    Location
    Here
    Posts
    1,010
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem isn't with the Javascript. Using the Javascript I have I can get the GMT values. The problem is that once I have the GMT offset, I need to be able to convert ASP dates to GMT dates and use the offset accordingly.

    Sample Code
    [vbs]


    intGMTOffset = Request.QueryString("GMTOffset")
    strJSDate = Request.QueryString("JDate")
    strVBDate = Now()

    ' Here I need to convert the JSDate using intGMTOffset and the VBDate using the servers offset

    [/vbs]

    Make any sense? Thanks,

  6. #6
    SitePoint Wizard wdmny's Avatar
    Join Date
    Jul 2000
    Location
    Here
    Posts
    1,010
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well nevermind. I have solved the problem by moving all the date code into the ASP script and using cookies, therefore eliminating the timezone difference, as all dates/times are based off the server only.


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
  •