javascript 有没有办法在javascript中获取当前时区?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13365399/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 18:34:08  来源:igfitidea点击:

Is there any way to get current timezone in javascript?

javascript

提问by Toseef Zafar

Possible Duplicate:
Getting the client's timezone in JavaScript

可能的重复:
在 JavaScript 中获取客户端的时区

Is there anyway to get current timezone in javascript. All i see is

无论如何可以在javascript中获取当前时区。我所看到的只是

Date.getTimeZoneOffset()

The problem I am facing is, I have a piece of functionality which allows the users to download pdf, now the pdf has to include a 'download date' in it which should be users local date, have to do this in java. But its all confusing, I dont know if i should locale or not or just the timezone will work, each time when i try something the results are different!!!!

我面临的问题是,我有一个功能允许用户下载 pdf,现在 pdf 必须包含一个“下载日期”,它应该是用户本地日期,必须在 java 中执行此操作。但这一切都令人困惑,我不知道我是否应该进行语言环境设置,或者只是时区会起作用,每次我尝试一些东西时结果都不一样!!!!

回答by Anirudh Ramanathan

Use Date.toTimeString()

利用 Date.toTimeString()

Code:

代码:

var date = new Date();
document.write(date.toTimeString());

Output:

输出:

22:53:21 GMT+0530 (India Standard Time)
              ^offset     ^timezone