不同当地时间的一天数据

发布于 2024-09-24 20:31:23 字数 112 浏览 5 评论 0原文

我有一个 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 技术交流群。

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

发布评论

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

评论(3

若水般的淡然安静女子 2024-10-01 20:31:23

这要看情况。

  1. 如果“一天的价值”表示“过去 24 小时”,那么他们都会看到相同的数据。
  2. 如果“一天的价值”表示“用户本地时区(当前日期 - 1)的 00:00-23:59”,那么他们可能会看到不同的数据。

示例:

      event 1      event 2       +---- service request
         |            |          v

|---------------|---------------|-  days in Central Europe

--------|-----------------|-------  days in the US (Pacific time)

---------------|---------------|--  UTC day boundaries

在情况 1 中,您只需返回服务请求后 24 小时即可。很容易看出,美国客户和欧洲客户都会获得相同的事件列表。

对于情况 2,情况更加困难:相对于美国时间,事件 1 和事件 2 在同一天发生。对于欧洲,这两个事件发生在不同的日子,因此美国客户和欧洲客户的结果会有所不同。

That depends.

  1. If "a day's worth" means "the last 24 hours", then they will both see the same data.
  2. If "a day's worth" means "00:00-23:59 of (current date - 1) in the user's local time zone", then they might see different data.

Example:

      event 1      event 2       +---- service request
         |            |          v

|---------------|---------------|-  days in Central Europe

--------|-----------------|-------  days in the US (Pacific time)

---------------|---------------|--  UTC day boundaries

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.

匿名。 2024-10-01 20:31:23

如果没有更多细节,答案是两者兼而有之。

  1. 如果在本地时区中定义了一天,然后在向数据库发出请求之前更改为 UTC 格式,则它们将具有不同的数据集。

  2. 如果查询类似于

    select * from dbTable where TimeStamp >= '9/22/2010' 并且 TimeStamp < “2010 年 9 月 23 日” 
    

    select * from dbTable where TimeStamp >= GetDate() - '24:00:00' 并且 TimeStamp <获取日期() 
    

    那么它们将为两个时区返回相同的数据集。

Without further details the answer is both.

  1. 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.

  2. if the query is somthing like

    select * from dbTable where TimeStamp >= '9/22/2010' and TimeStamp < '9/23/2010' 
    

    or

    select * from dbTable where TimeStamp >= GetDate() - '24:00:00' and TimeStamp < GetDate() 
    

    then they will return the same set of data for both time zones.

月隐月明月朦胧 2024-10-01 20:31:23

这当然是可能的——这是全球化/本地化的常见问题之一。
重要的是在进行查询之前将所有请求转换为 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.

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