如何在浏览器中使用自定义时间来测试客户端与服务器的时间差 [英] How to use a custom time in browser to test for client vs server time difference

查看:20
本文介绍了如何在浏览器中使用自定义时间来测试客户端与服务器的时间差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚写了一小段代码来显示网页中的服务器时间.目前我只有一台机器,所以我无法测试代码是否正常工作.

I just wrote a little piece of code to show the server time in a webpage. At the moment I just have one machine so I cannot test if the code is working.

有没有办法告诉浏览器使用不同于操作系统中配置的时间配置?我已经使用 Firefox 的插件来测试不同的语言环境,不知道是否有类似的时间测试选项.

Is there a way to tell the browser to use a time configuration different from the one configured in the OS? I have used plugins for Firefox to test different locales, I wonder if there are similar options for time tests.

谢谢.

推荐答案

不幸的是,JavaScript 只知道当前时区,因为它是由操作系统设置的.没有工具可以让 Date 对象在特定上下文中使用不同的时区.一些库可以进行时区转换,但这对您的要求没有帮助.

Unfortunately, JavaScript is only aware of the current time zone, as it is set by the operating system. There are no facilities to let the Date object use a different time zone in a particular context. There are some libraries to do time zone conversions, but that won't help for what you are asking.

在 Linux、Mac OSX 和其他 *NIX 系统上,您可以设置 TZ 环境变量.有关详细信息,请参阅 Benedikt Köppel 的回答.

On Linux, Mac OSX, and other *NIX systems, you can set the TZ environment variable. See Benedikt Köppel's answer for details.

但是,Windows 上没有此功能.一些 Windows 程序可能会使用 TZ 环境变量,但那些这样做的程序不一定会正确解释它,因为它们没有连接到支持 IANA 时区名称.更多关于这个这里这里.

However, there is no facility for this on Windows. Some Windows programs may pick up on the TZ environment variable, but those that do will not necessarily interpret it correctly, as they aren't wired up to support IANA time zone names. More on this here and here.

这篇关于如何在浏览器中使用自定义时间来测试客户端与服务器的时间差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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