C# UTC DateTime query in WCF/.NET

送分小仙女□ 提交于 2019-12-01 22:40:24

Instead of using the DateTime structure, you should use the DateTimeOffset structure.

The DateTimeOffset structure captures the offset from a specified time (it's not UTC by default, it's defined by the scope of your application, but the most common offset would be from UTC) along with the date/time information, and that information will flow through WCF calls (as well as to a database, assuming it supports the type. SQL Server in this case has the datetimeoffset data type from 2008 on).

As a matter of fact, using DateTimeOffset is the preferred methods of dealing with date/time data in almost all situations. Note from the previous link:

These uses for DateTimeOffset values are much more common than those for DateTime values. As a result, DateTimeOffset should be considered the default date and time type for application development.

If your server's timezone is on Lisbon/London/Dublin time, it is not UTC. You will either want to change the time zone of your server, or express the date/time value in UTC form when you update it in your database.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!