我应该使用哪种 SQL 数据类型来存储 GPS 设备的日期时间?

发布于 2024-12-26 01:36:22 字数 243 浏览 1 评论 0原文

我正在开发一个项目,必须从位于不同国家/地区(时区+夏令时)的 GPS 设备收集数据,并将这些数据显示给来自不同国家/地区的不同用户。我正在考虑以 UTC 格式保存日期(这是我从 GPS 设备收到的日期),但我再次相信,将该日期转换为用户的本地日期时会遇到麻烦(我还必须显示历史数据,所以我必须考虑给定日期的夏令时)。也许 datetimeoffset 数据类型会更合适,但我如何将接收到的 UTC 日期转换为 datetimeoffset 数据类型?你有什么建议?谢谢!

I'm working on a project where I have to gather data from GPS devices located in different countries (timezones + daylight savings) and display those data to different users also from different countries. I'm thinking about saving the date in UTC format (that is what I receive from the GPS device) but then again I belive I'll have trouble converting that date to the user's local date (I have to display historical data also so I'll have to account for daylight savings for the given date). Maybe the datetimeoffset datatype would be more appropriate but how would I go about converting the received UTC date to the datetimeoffset datatype? What would you suggest? Thanks!

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

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

发布评论

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

评论(1

初见 2025-01-02 01:36:22

由于您不必将任何时区与日期时间一起存储,因此可以将它们存储为 UTC。这样做的优点是线性且易于记录。您不必担心夏令时切换时的间隙和重叠。

当您向用户显示日期时,将日期转换为本地时区。在您知道哪个用户将查看数据之前,将其转换为本地时区是没有意义的。

As you don't have to store any time zone along with the datetime, you can store them as UTC. That has the advantage of being linear, and easy to document. You don't have to bother with gaps and overlaps at the daylight savings time switches.

Convert the date to the local time zone when you display it to the user. It doesn't make sense to convert it to a local time zone until you know which user will be viewing the data.

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