JavaScript日期/时间函数是否依赖于客户机? [英] Are Javascript date/time functions dependent on the client machine?

查看:113
本文介绍了JavaScript日期/时间函数是否依赖于客户机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道JavaScript日期/时间函数是否始终返回正确的,通用的日期/时间
或者,Javascript是客户端语言,它们取决于客户端机器的日期设置为。

I was wondering if Javascript date/time functions will always return correct, universal dates/times or whether, Javascript being a client-side language, they are dependent on what the client machine has its date set to.

如果它依赖于客户机,什么是获得正确的世界时间的最佳方式?

If it is dependent on the client machine, what is the best way to get the correct universal time?

推荐答案

由于thomasrutter表示JavaScript日期功能依赖于客户机的机器。但是,如果要获得权威日期,您可以向服务器发出只要返回日期字符串的ajax请求。然后,您可以将日期字符串转换为日期对象,具有以下

As thomasrutter has said javascript date functions are reliant on the client's machine. However if you want to get an authoritative date you could make and ajax request to your server that just returns the date string. You can then convert the date string into a date object with the following

var ds = ... // Some ajax call
var d = new Date(ds);

这篇关于JavaScript日期/时间函数是否依赖于客户机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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