Skip to content

Instantly share code, notes, and snippets.

@andirkh
Created August 4, 2020 06:01
Show Gist options
  • Save andirkh/e40aa10b501d656d809dccf316caf365 to your computer and use it in GitHub Desktop.
Save andirkh/e40aa10b501d656d809dccf316caf365 to your computer and use it in GitHub Desktop.
function TimezoneDetect(){
var dtDate = new Date('1/1/' + (new Date()).getUTCFullYear());
var intOffset = 10000;
var intMonth;
var intHoursUtc;
var intHours;
var intDaysMultiplyBy;
// Go through each month to find the lowest offset to account for DST
for (intMonth=0;intMonth < 12;intMonth++){
//go to the next month
dtDate.setUTCMonth(dtDate.getUTCMonth() + 1);
// To ignore daylight saving time look for the lowest offset.
// Since, during DST, the clock moves forward, it'll be a bigger number.
if (intOffset > (dtDate.getTimezoneOffset() * (-1))){
intOffset = (dtDate.getTimezoneOffset() * (-1));
}
}
return intOffset / 60;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment