www.webdeveloper.com
Page 3 of 3 FirstFirst 123
Results 31 to 38 of 38

Thread: Servertime Count problem

  1. #31
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,266
    Where do you live ? In witch time zone ? London ?
    For me the difference is 2 and will be 1 tomorrow, with the end of the daylight saving time.
    Your test will not change and give always an alert.

  2. #32
    Join Date
    Jan 2009
    Location
    Insanity
    Posts
    1,131
    I added an alert.
    Code:
    dObj = new Date();
    dslChk = (dObj.getUTCHours() - dObj.getHours());
    if(dslChk){
    	 alert("Day Light Savings is observed on this machine at the moment");
    }else{
    	 alert("Here's Winter... DLS ended\r\nthe difference is: "+dslChk+" Hrs between UTC & GMT");
    }
    And these are my findings.
    Attached Images Attached Images
    We all have baggage to carry in life, unfortunately for me I always get the trolley with the wonky wheel...
    Code:
    Youre = {
          STILL_not_getting_it:function(){
               alert("YOU, the original poster / thread starter NEED to POST the code and NOT a LINK.");
          },
          MissingThePoint:function(msg){
                alert("You're missing the point. " + msg);
          }
    }
    Youre.STILL_not_getting_it();

  3. #33
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,266

    Day Light saving or not ?

    Your test is only valid in Greenwich Mean Time zone !
    It's the difference between UTC and local time in summer and in winter wich can help to know if the DSL is or not observed.

    Code:
    <script type="text/javascript">
    dObj = new Date();
    dltObj = (dObj.getUTCHours() - dObj.getHours());
    datSummer = new Date(dObj.getFullYear(),5,21,12,0,0);// difference on June 21
    datWinter = new Date(dObj.getFullYear(),11,21,12,0,0);// difference on december 21
    dltSummer = (datSummer.getUTCHours() - datWinter.getHours());
    dltWinter = (datWinter.getUTCHours() - datWinter.getHours()); 
    
    if(dltSummer!=dltWinter){msg="Day Light Savings is observed in your time zone...";
    	if (dltSummer==dltObj) msg += "\nDay Light Savings is observed at the moment.";
    	else msg += "\nDay Light Savings is not observed at the moment.";}
    else msg = "Day Light Savings is not observed in your time zone !";
    alert(msg);	 
    </script>

  4. #34
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,266
    Two interesting links for further development with time zones Auto detect a time zone with JavaScript and a jsTimeZoneDetect script.
    The differences between local time and UTC are given (in minutes) directly by an dObj.getTimezoneOffset().
    Last edited by 007Julien; 11-01-2011 at 06:48 PM.

  5. #35
    Join Date
    Jan 2009
    Location
    Insanity
    Posts
    1,131
    Quote Originally Posted by 007Julien View Post
    Two interesting links for further development with time zones Auto detect a time zone with JavaScript and a jsTimeZoneDetect script.
    The differences between local time and UTC are given (in minutes) directly by an dObj.getTimezoneOffset().
    Yes I stated that in a previous post.

    What people need to understand is that its the time on the LOCAL machine obtained by a date object, compare this with a time reference GMT to get any DLS offset.

    So if the users machine ia in a timezone +6hr from GMT then the local area observes DLS, the local machine would return a +1 hour difference based on the local machines DLS rules or observations.

    This however is not 100% in any measurement system devised to tell if DLS is in effect becayse some countries fluctuate and have no set rule, many do not and it would be dependent on the user changing the clock.

    This is why UTC exists because it does not observe any movement forward or back in time. if you want to know more about UTC go here
    We all have baggage to carry in life, unfortunately for me I always get the trolley with the wonky wheel...
    Code:
    Youre = {
          STILL_not_getting_it:function(){
               alert("YOU, the original poster / thread starter NEED to POST the code and NOT a LINK.");
          },
          MissingThePoint:function(msg){
                alert("You're missing the point. " + msg);
          }
    }
    Youre.STILL_not_getting_it();

  6. #36
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,266
    Let's be clear, we work with javascript and do not make literature...

    1/ - With javascript toGMTString() and toUTCString() give exactly the same date. Only the terms GMT or UTC change (see this page).
    2/ - The only difference is that toGMTString() is deprecated (see the list of Date object methods on this page).
    3/ - The difference between UTC and Local time is done by getTimezoneOffset().
    4 / The following script (which come from this page), with comments for Alaska, shows the method to determine DSL, hemisphere (the sign of the difference is significant) and the common denominator for the time zone (the true timezoneOffset ?).

    Code:
    function get_timezone_info() {
        // Alaska offset in january is -540 minutes from UTC
        var january_offset = - new Date(2011,0,1,0,0,0,0).getTimezoneOffset(); 
        // Alaska offset in june is -480 minutes from UTC
        var june_offset = - new Date(2011,5,1,0,0,0,0).getTimezoneOffset(); // returns 480
        // There's a -60 minutes offset difference between january and june in Alaska
        var diff = january_offset - june_offset; 
        // Diff = -60, so we know that this region uses daylight savings,
        // and is in the northern hemisphere. Also we know that the January
        // offset is the common denominator for the timezone, i.e 540 minutes = 9 hours
        if (diff < 0) {
            return {'utc_offset' : january_offset,
                    'dst':  1,
                    'hemisphere' : 'HEMISPHERE_NORTH'}
        }
        // This is where we end up for southern hemisphere daylight savings time zones
        else if (diff > 0) {
            return {'utc_offset' : june_offset,
                    'dst' : 1,
                    'hemisphere' : 'HEMISPHERE_SOUTH'}
        }
        // this is returned for non DST time zones
        return {'utc_offset' : january_offset, 
                'dst': 0, 
                'hemisphere' : 'HEMISPHERE_UNKNOWN'}
    }
    
    Object.prototype.toString=function(){var i,c='Object get_timezone_info';for (i in this) c+='\n'+i+' => '+this[i];return c}
    alert(get_timezone_info().toString());

  7. #37
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    One never be able to know if the user has set correctly his computer's time/zone/clock and whether his country's DST adjustment is on or off, thus the client's clock will never be 100&#37; deductible. There is absolutely no way to fight against the human error, at least not in this case

    You may, probably, detect his IP on the server-side and deduct the country/zone, but nor even this method is 100% accurate. The user might be connected trough a proxy, thus your server will see the IP of the proxy, not of the user...
    Last edited by Kor; 11-03-2011 at 09:00 AM.

  8. #38
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,266
    Obviously ! I wrote &#171;there is so many Universal Time that servers or machines &#187; (a little bit excessive for servers after checks, however only a stopped watch give the exact time twice a day !). I simply wanted not to let believe that the simplistic method proposed by JunkMale was valid.

    Thanks for your intervention.
    Last edited by 007Julien; 11-03-2011 at 10:24 AM. Reason: complement

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles