franga2000
12/2/2014 - 3:12 PM

Functions to process time and time zones

Functions to process time and time zones

//Get UTC/GMT Offset
new Date().getTimezoneOffset() / -60; /* Type: integer */

//Get timezone offset string: GMT, GMT+01:00, GMT-01:30
function getTimeZoneString() {
	var num = new Date().getTimezoneOffset();
	if (num === 0) {
		return "GMT";
	} else {
		var hours = Math.floor(num / 60);
		var minutes = Math.floor((num - (hours * 60)));

		if (hours < 10) hours = "0" + Math.abs(hours);
		if (minutes < 10) minutes = "0" + Math.abs(minutes);
		
		return "GMT" + (num < 0 ? "+" : "-") + hours + ":" + minutes;
	}
}