时区计算
正在开发在线旅游门户之类的网站。该问题是在航班预订时显示各个地区的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然在不参考特定技术的情况下很难回答你的问题,但我会尝试。
最终用户时区检测
当然,所有与时间相关的信息都应以本地格式和本地时区呈现>。我所说的本地是指最终用户使用的。
我猜您的应用程序不需要创建用户配置文件。我还假设航班时刻表在首页上不可见,用户需要执行搜索。在这种情况下,您有三种选择:
让用户从下拉框中指定时区。如果不参考具体技术,我无法向您展示应该如何完成。我唯一必须指出的是,它应该显示 UTC 偏移量、时区名称和城市列表,例如:UTC+01:00 中欧时间(巴黎、柏林、华沙)。< /p>
您可以使用 JavaScript 读取当前时区偏移并将其发送到服务器
在这种情况下,您可以使用以下代码片段来检测偏移:
这将为您提供当前 GMT 偏移量(以分钟为单位)。该解决方案的问题是,此偏移量在目标日期可能会有所不同。
日期和时间格式化以及时区转换
哈,这取决于您想要实现的解决方案以及您想要使用的技术。目前,我不能在这里写太多。
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:
This will give you current GMT offset in minutes. The problem with that solution is, this offset might be different on the target date.
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.