时区计算

发布于 2024-11-09 10:51:43 字数 85 浏览 0 评论 0原文

正在开发在线旅游门户之类的网站。该问题是在航班预订时显示各个地区的 GMT 时间并列出时间。有人能给出计算和显示不同国家时间的想法吗?

谢谢

Am developing website like online travel portal. The issue is displaying GMT time for various regions at flight booking and list out the timing. Any one gives idea to calculate and show the time for different countries?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许一世地老天荒 2024-11-16 10:51:43

虽然在不参考特定技术的情况下很难回答你的问题,但我会尝试。

最终用户时区检测

当然,所有与时间相关的信息都应以本地格式本地时区呈现>。我所说的本地是指最终用户使用的。
我猜您的应用程序不需要创建用户配置文件。我还假设航班时刻表在首页上不可见,用户需要执行搜索。在这种情况下,您有三种选择:

  • 让用户从下拉框中指定时区。如果不参考具体技术,我无法向您展示应该如何完成。我唯一必须指出的是,它应该显示 UTC 偏移量、时区名称和城市列表,例如:UTC+01:00 中欧时间(巴黎、柏林、华沙)。< /p>

  • 您可以使用 JavaScript 读取当前时区偏移并将其发送到服务器

在这种情况下,您可以使用以下代码片段来检测偏移:

var now = new Date();
var offset = now.getTimezoneOffset();

这将为您提供当前 GMT 偏移量(以分钟为单位)。该解决方案的问题是,此偏移量在目标日期可能会有所不同。

  • 显然,您也可以将基于 GMT 的日期以不变的形式发送到浏览器(例如使用 ISO8601 格式:2011-05-25T11:07Z),并使用 JavaScript 在客户端上格式化该日期。不过,我从未听说过 JQuery 插件可以正确(尊重本地格式)。看来您将被迫自己编写。

日期和时间格式化以及时区转换

哈,这取决于您想要实现的解决方案以及您想要使用的技术。目前,我不能在这里写太多。

Although it is pretty hard to answer your question without a reference to particular technology, I will try.

End user Time Zone detection

Definitely, all time-related information should be presented both in local format and local time zone. By local I mean the one used by end user.
I am guessing that your application will not require creating user profiles. I am also assuming that flight schedules will not be visible on front page and user would need to perform search. In that case you have three choices:

  • Let user specify time zone from drop down box. I have no way to show you how it should be done without referring to concrete technology. The only thing I must point out is, it should present UTC offset, time zone name and list of cities, for example: UTC+01:00 Central European Time (Paris, Berlin, Warsaw).

  • You could read current time zone offset with JavaScript and send it out to server

In that case you can use following code snippet to detect offset:

var now = new Date();
var offset = now.getTimezoneOffset();

This will give you current GMT offset in minutes. The problem with that solution is, this offset might be different on the target date.

  • Obviously you could as well send GMT based dates in invariant form to the browser (for example using ISO8601 format: 2011-05-25T11:07Z) and format this date on the client using JavaScript. I never heard of for example JQuery plugin which would do that correctly (respecting local formats), though. It seems that you would be forced to write your own.

Date and time formatting as well as time zone conversion

Ha, it depends on solution you want to implement as well as technology you want to use. For now, I can't write much here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文