如何在我的 webapp 中处理时区? [英] How can I handle time zones in my webapp?

查看:20
本文介绍了如何在我的 webapp 中处理时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望更好地理解以下用户故事:

I'm looking for better understanding of the following user story:

约翰在悉尼工作.早上 9:00,他在苏黎世服务器上运行的 Web 应用程序中记录了一个事件.第二天,他前往纽约参加应讨论该事件的紧急会议.在会议期间,他按日期和时间搜索事件.

John works in Sidney. At 9:00 in the morning, he logs an event in a web app that runs on a server in Zurich. The next day, he travels to New York for an emergency meeting in which the event should be discussed. During the meeting, he searches for the event by date and time.

在我看来,这里至少有两个问题:

As I see it, there are at least two issues here:

  1. 我应该如何将时间戳保存在数据库中
  2. 我应该如何在 UI 中展示它们

当约翰搜索事件时,他会知道事件发生在 9:00,但他应该在网络浏览器中输入什么?当他只是输入9:00"作为时间戳时,他将找不到任何东西,因为那可能是苏黎世或纽约时间(由于尚未找到该事件,该应用程序无法知道它发生在 Sidney,所以它不能自动选择正确的时区).

When John searches the event, he will know that it happened at 9:00 but what should he enter in the web browser? He won't find anything when he just enters "9:00" as timestamp because that might be Zurich or New York time (since the event hasn't been found, the app has no way to know that it happened in Sidney, so it can't automatically select the correct time zone).

向用户询问可能包含时区的时间戳的好方法是什么?

What is a good way to ask the user for a timestamp that might include the time zone?

第二个问题是如何显示结果.如果来自全球各地的团队需要讨论该事件(并查找相关事件,请考虑一次针对全球多个站点的黑客攻击).

The second issue is how to display the results. If teams from all over the globe need to discuss the event (and find related events, think of a cracker attack that targets several sites all over the globe at once).

显示可能在不同时区创建的时间戳的好例子是什么?

What is a good example for displaying timestamps that might have been created in a different time zone?

注意:请专注于需求的可用性.我可以自己弄清楚数据库映射.目前,我不确定工作流程.它应该以非侵入性/直观的方式询问/呈现必要的信息.如果可以,请提供一个指向已经解决此问题的现有网络应用程序的链接.

Note: Please concentrate on the usability of the requirement. I can figure out the database mapping myself. Currently, I'm unsure about the work flow. It should ask/present the necessary information in an non-intrusive/intuitive way. If you can, give a link to an existing web app which already solves this.

推荐答案

存储时间戳的问题很简单:以UTC格式存储.

The issue of storing timestamps is simple: Store them in UTC.

至于显示它们,采用设备的时区设置并将其用作当前时区是有意义的.也就是说,时间输入"框旁边应该有一个时区下拉菜单,默认为设备的当前时区,因此用户可以根据需要进行更改.

As for displaying them, it would make sense to take the device's timezone setting and use that as the current timezone. That said, there should be a timezone dropdown next to the "time input" box, which defaults to the device's current timezone, so the user can change it if needed.

您的大多数用户可能不会或根本不会更改时区.在大多数情况下,您概述的情况并不常见.通过实施具有合适默认值的下拉菜单,您应该能够为那些四处走动的人提供足够的便利(因为他们通常比非旅行者更了解时区).

The majority of your users probably will not change timezones much, or at all. For the most part, the situation you outlined is uncommon. By implementing a dropdown with a suitable default, you should be able to make things easy enough for those who do move around (because they typically have a better understanding of timezones than a non-traveller would).

事实上,更好的做法是保存您的应用首次运行时设备设置的时区,然后查看它是否会更改.如果它确实发生了变化,那么用户可能是一名旅行者,并且可能会从时区下拉列表中受益.否则,只是不显示下拉菜单并默认为设备时区(因为用户不需要知道它们).无论哪种情况,在应用程序中设置一个允许用户手动显示/隐藏时区下拉菜单的设置.

In fact, even better would be to save the timezone the device was set to when your app was first run, and then see if it ever changes. If it does change, then the user is probably a traveller and would probably benefit from having the timezone dropdown. Otherwise, just don't show the dropdown and default to the device timezone (because the user doesn't need to know about them). In either case, have a setting in the app that allows the user to manually show/hide the timezone dropdown.

总结以上内容:

  • 首次运行时,保存设备设置的时区.
  • 使用该时区作为默认时区.始终假定该时区.
  • 如果设备切换时区,添加一个下拉菜单以选择事件所在的时区,默认为设备自己的时区.
  • 添加一个选项以手动显示/隐藏此时区下拉菜单.
  • 始终以 UTC 格式存储时间戳.

这篇关于如何在我的 webapp 中处理时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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