Can JavaScript determin what time zone the clients browsers in?

Discussion in 'JavaScript' started by unitedlocalbands, Sep 18, 2007.

  1. #1
    I would like to find a way to determin what time zone or what the time zone offset is related to "GMT"

    I know I need a client side script and from what I understand about javascript is that it most certenly is client side.

    Any suggestion on how to determin the client time zone offset from "GMT" and then send it back to server side so that I can store that as a cookie whenever a user logs into my website would be great.

    Once I get the "offset" back to the server I should be ok.

    I use coldfusion just in case anyone knows a way to do it with just coldfusion although like I said I think I need client side script to make this work.


    Thanks a bunch!
     
    unitedlocalbands, Sep 18, 2007 IP
  2. Mike H.

    Mike H. Peon

    Messages:
    219
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Don't divide it by 60 if you would prefer the value to be in minutes, instead of hours.

    
    
    <script type="text/javascript">
    
    	function xmitOffset(){
    
    		var refDate = new Date();
    		var gmtOffset = refDate.getTimezoneOffset() / 60;
    		var AdminRequest = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();   
    		AdminRequest.open("GET", "saveUserOffset.php?offset="+gmtOffset, true);
    		AdminRequest.send(null); 
    	}
    
    	onload=xmitOffset;
    	
    </script>
    
    Code (markup):

    saveUserOffset.php:
    
    $userGMTOffset = $_GET['offset'];
    Code (markup):
     
    Mike H., Sep 18, 2007 IP
  3. unitedlocalbands

    unitedlocalbands Well-Known Member

    Messages:
    246
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    128
    #3
    Thank you for the javascript.

    This is a big help to making my website more globalized!

    James C
     
    unitedlocalbands, Sep 18, 2007 IP