如何使用javascript获取用户时区的字符串表示? [英] how do I get the string representation of the users timezone using javascript?

查看:164
本文介绍了如何使用javascript获取用户时区的字符串表示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想输出用户系统时区,例如美东时间。如何做到这一点,最好使用Javascript,虽然我也可以在PHP方面做到这一点,如果这样做比较容易一些。

I want to output the users system timezone, e.g. "EST". How can I do that, preferably using Javascript, though I could do it on the PHP side as well, if that's significantly easier.

推荐答案

p>您将不得不使用Javascript - 因为您不知道服务器端的客户端时区。您可以使用下面的代码,并从本地时间提取相关的时区字符串。

You will have to use Javascript - since you do not know the client timezone on the server side. You could use the code below and extract the relevant timezone string from localtime.

var now = new Date();
localtime = now.toTimeString();

这将返回类似12:21:44 GMT-0400(EDT)

which will return something like "12:21:44 GMT-0400 (EDT)"

这篇关于如何使用javascript获取用户时区的字符串表示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆