I want to get the users timezone in relation to UTC and then display it UTC +/- . for example a California user should show UTC -8 (or -7 depending), while Bahrain would show UTC +3, etc.
The following code doesn't tell me if it's plus or minus tho, it just gives the answer 7 at the moment. How do I get it to give me a plus or minus sign?
var offset = new Date().getTimezoneOffset();
document.write(offset / 60);
It is very simple.
var offset = - new Date().getTimezoneOffset(); document.write((offset > 0 ? '+' : '') + offset / 60);