window.onload = function() { //TODO begin 處理登陸使用者時區 //獲得登陸使用者時區與GMT時區的差值 var exp = new Date(); var gmtHours = -(exp.getTimezoneOffset()/60); setCookie('customer_timezone',gmtHours,1); //判斷是否為夏令時 date = exp.format('yyyy-MM-dd HH:mm:ss'); if(inDaylightTime(date)){ setCookie('inDaylightTime',1,1); } } //設定Cookie function setCookie(c_name,value,expiredays){ var exdate=new Date() exdate.setDate(exdate.getDate()+expiredays) document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : "; expires="+exdate.toGMTString()) } //判斷時間是東半球還是西半球 function isEastEarthTime(newDate) { var dj= newDate.getGMTOffset(false); if (dj.indexOf("-") == -1){ return true; } else { return false; } } //是否是夏令時 function inDaylightTime(date){ var start = new Date(date.getTime()); start.setMonth(0); start.setDate(1); start.setHours(0); start.setMinutes(0); start.setSeconds(0); var middle = new Date(start.getTime()); middle.setMonth(6); // 如果年始和年中時差相同,則認為此國家沒有夏令時 if ((middle.getTimezoneOffset() - start.getTimezoneOffset()) == 0) { return false; } var margin = 0; if (this.isEastEarthTime(date)) { margin = middle.getTimezoneOffset(); } else { margin = start.getTimezoneOffset(); } if (date.getTimezoneOffset() == margin) { return true; } return false; } //DONE end |