1// White Papers 2// Time Zone Calculation 3// http://www.desisoftsystems.com/white-papers/timeZoneCalculation/ 4// 5// Conclusion 6// In the interest of promoting open standards, you are free to use 7// the source code in this white paper and the code available in this JavaScript source file: 8// 9// http://www.desisoftsystems.com/tzCalculation_LocalTimeZone.js 10// 11// to implement this solution to this world-wide problem. 12// 13function tzCalculation_LocalTimeZone ( 14 theDomainForTheCookie, 15 printTheTimeZone) 16{ // Beginning of tzCalculation_LocalTimeZone 17 var rightNow; 18 var rightNow_UTC_MillisecondsSinceTimBegan; 19 var rightNow_Local_MillisecondsSinceTimBegan; 20 var rightNow_MillisecondsDifference; 21 var rightNow_MinutesDifference; 22 var rightNow_timeZoneString; 23 var rightNow_MinutesPart; 24 var rightNow_HoursDifference; 25 26 rightNow = new Date(); 27 28 rightNow_UTC_MillisecondsSinceTimBegan = Date.UTC ( 29 rightNow.getUTCFullYear (), 30 rightNow.getUTCMonth (), 31 rightNow.getUTCDate (), 32 rightNow.getUTCHours (), 33 rightNow.getUTCMinutes (), 34 rightNow.getUTCSeconds () 35 ); 36 rightNow_Local_MillisecondsSinceTimBegan = Date.UTC ( 37 rightNow.getFullYear (), 38 rightNow.getMonth (), 39 rightNow.getDate (), 40 rightNow.getHours (), 41 rightNow.getMinutes (), 42 rightNow.getSeconds () 43 ); 44 45 rightNow_MillisecondsDifference = rightNow_Local_MillisecondsSinceTimBegan - rightNow_UTC_MillisecondsSinceTimBegan; 46 47 rightNow_MinutesDifference = (rightNow_MillisecondsDifference / 1000) / 60; 48 49 if (0 > rightNow_MinutesDifference) 50 { 51 rightNow_timeZoneString = "-"; 52 } 53 else 54 { 55 rightNow_timeZoneString = "+"; 56 } 57 58 rightNow_MinutesPart = rightNow_MinutesDifference % 60; 59 60 if (rightNow_MinutesPart != 0) 61 { 62 rightNow_MinutesDifference -= rightNow_MinutesPart; 63 64 if (0 > rightNow_MinutesPart) 65 { 66 rightNow_MinutesPart = Math.abs (rightNow_MinutesPart); 67 } 68 } 69 70 if (0 > rightNow_MinutesDifference) 71 { 72 rightNow_MinutesDifference = Math.abs (rightNow_MinutesDifference); 73 } 74 75 rightNow_HoursDifference = rightNow_MinutesDifference / 60; 76 77 if (10 > rightNow_HoursDifference) 78 { 79 rightNow_timeZoneString = rightNow_timeZoneString + '0'; 80 } 81 82 rightNow_timeZoneString = rightNow_timeZoneString + rightNow_HoursDifference; 83 84 if (10 > rightNow_MinutesPart) 85 { 86 rightNow_timeZoneString = rightNow_timeZoneString + '0'; 87 } 88 89 rightNow_timeZoneString = rightNow_timeZoneString + rightNow_MinutesPart; 90 91 if (printTheTimeZone) 92 { 93 document.writeln (rightNow_timeZoneString); 94 } 95 96 document.cookie = 'timezone=' + rightNow_timeZoneString + '; domain=' + theDomainForTheCookie; 97 98 return rightNow_timeZoneString; 99} // End of tzCalculation_LocalTimeZone
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.