Javascript get client timezone

From Attias

Jump to: navigation, search
<script language="JavaScript">

	function getTimeZone(){
               var visitortime = new Date();
               //get timezone from date with regexp
               var timeZoneStr = visitortime.toString().replace(/^.*\(|\)$/g, "").replace(/[^A-Z]/g, "");
		// timeZoneStr  should be CST .....
               // in my case TFCST so I 
               if(timeZoneStr.length > 3)substring
			return timeZoneStr.substring(2);
		return timeZoneStr;
	}  
       ....


Call to the function

document.write('
date: ' + new Date()); document.write('
date timeZone: ' + getTimeZone());

Output

date: Tue Feb 9 13:41:32 CST 2010
date timeZone: CST
Personal tools
All pages
Pictures
art