Get client timezone (not GMT offset amount) in JS

后端 未结 5 2123
时光说笑
时光说笑 2020-12-14 18:04

I need to determine the client timezone (e.g. CET, GMT, EST) in JS. Getting the offset is straightforward, but doesn\'t have all the info necessary to determine the TZ, at l

5条回答
  •  感动是毒
    2020-12-14 18:38

    Starting from this answer to another question, I found that IP API also gives you the timezone – pretty handy:

    $.ajax({
        url: "http://ip-api.com/json",
        type: 'GET',
        success: function(json) {
            console.log("Timezone: " + json.timezone);
        },
        error: function(err) {
            console.log("Request failed, error= " + err);
        }
    });
    

提交回复
热议问题