简体   繁体   English

如何在JS中为日期选择器而不是浏览器设置时区

[英]How to set Timezone for Date Picker instead of browser in js

I want to set the Timezone for Date picker in java script. 我想在Java脚本中为Date选择器设置时区。 It seems it always takes time from the browser which is running on it. 似乎从浏览器上运行总是要花费一些时间。

For eg My OS Date is set to : July 5,2015 例如, 我的操作系统日期设置为 :2015年7月5日

Current Date : 24 Oct 2015 当前日期 :2015年10月24日

Whenever i try to open the Date Picker. 每当我尝试打开日期选择器时。 It shows July 5,2015 as current date instead of the Oct 24,2015. 它显示2015年7月5日为当前日期,而不是2015年10月24日。

JavaScript runs on the client machine, as such it will get the date from the client machine. JavaScript在客户端计算机上运行,​​因此它将从客户端计算机获取日期。 If your machine is not configured correctly (as it sounds yours is not), the date returned will be incorrect. 如果您的机器配置不正确(听起来好像不是您的机器),则返回的日期将不正确。 You need to query whatever server you trust to have the correct date and use that result. 您需要查询任何您信任的服务器以获取正确的日期并使用该结果。

There are also Free APIs that serve up the time if you don't want to use your own server all over this post: Free Rest API to get current time as string (timezone irrelevant) 如果您不想在本篇文章中一直使用自己的服务器,也可以使用免费的API来节省时间免费的Rest API以字符串形式获取当前时间(与时区无关)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM