不同当地时间的一天数据
我有一个 winform 客户端和 wcf 服务,它们一起显示历史数据。使用 utc 时间戳存储在数据库中的数据。如果位于不同时区的两个客户端想要根据本地时间查看最近一天的数据,他们是否有可能查看不同的数据集?
I have a winform client and wcf service that together display historical data. the data stored in the db with utc timestamps. If two clients in different time zones want to look at a most recent day's worth of data based on their local time, can it be possible that they would be looking at different sets of data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这要看情况。
示例:
在情况 1 中,您只需返回服务请求后 24 小时即可。很容易看出,美国客户和欧洲客户都会获得相同的事件列表。
对于情况 2,情况更加困难:相对于美国时间,事件 1 和事件 2 在同一天发生。对于欧洲,这两个事件发生在不同的日子,因此美国客户和欧洲客户的结果会有所不同。
That depends.
Example:
In case 1, you just go back 24 hours from the time of the service request. It's easy to see that both customers, the one in the US and the one in Europe, will get the same list of events.
In case 2, it's more difficult: With respect to US time, events 1 and 2 happen on the same day. With respect to Europe, both events happen on different days, so the results will be different for the client in the US and the client in Europe.
如果没有更多细节,答案是两者兼而有之。
如果在本地时区中定义了一天,然后在向数据库发出请求之前更改为 UTC 格式,则它们将具有不同的数据集。
如果查询类似于
或
那么它们将为两个时区返回相同的数据集。
Without further details the answer is both.
If a day is defined in the local time zone then changed to the UTC format before the request to the db is made they will have different data sets.
if the query is somthing like
or
then they will return the same set of data for both time zones.
这当然是可能的——这是全球化/本地化的常见问题之一。
重要的是在进行查询之前将所有请求转换为 UTC 时间。如果查询全部基于 UTC,则返回到本地计算机的数据应该匹配,因为 UTC 时间将匹配。
It is certainly possible - it is one of the common issues with globalization/localization.
The important thing to do is to convert all requests to UTC time before making the query. If the queries are all UTC-based, then the data returned to the local machines should match, as the UTC times will match.