且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在注册表单中检测用户时区?

更新时间:2023-02-25 12:42:35

JavaScript:

var today = new Date();

alert( today.getTimezoneOffset() );

这将给出偏移量(GMT-X),而不是实际的时区名称.请记住,相同的GMT偏移量可以对应多个时区,并且还必须考虑夏令时.但是,这可能是最容易上手的地方,只是没有让用户从下拉列表中选择他们的时区.

This will give the Offset (GMT-X), but not the actual timezone name. Keep in mind same GMT offset can correspond with multiple timezones and also have to take into account Daylight savings. However, this is probably the easiest place to start, short of giving the users pick their timezone from a dropdown.