Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Client side time zone

Tags:

javascript

i want to store timezone of client (visitor) which going to use my web portal. would you please show me way to find out timezone for client machine using JAVAScript code...

I need the GMT offset hours like `(GMT +5:30)`.
like image 303
Vijay Avatar asked Dec 20 '22 03:12

Vijay


1 Answers

This could be a better approach to find client local time/offset

function pad(number, length){
    var str = "" + number;
    while (str.length < length) {
        str = '0'+str;
    }
    return str;
}
var offset = new Date().getTimezoneOffset();

offset = ((offset<0? '+':'-')+ pad(parseInt(Math.abs(offset/60)), 2)+":"+pad(Math.abs(offset%60), 2));
alert(offset);

The output would be like = +05:30

like image 164
Mehul Dudhat Avatar answered Jan 04 '23 21:01

Mehul Dudhat