我应该使用哪种 SQL 数据类型来存储 GPS 设备的日期时间?
我正在开发一个项目,必须从位于不同国家/地区(时区+夏令时)的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您不必将任何时区与日期时间一起存储,因此可以将它们存储为 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.