C# UTC DateTime query in WCF/.NET

后端 未结 2 1420
一生所求
一生所求 2021-01-21 03:41

This is a very simple, (hopefully) question. I am new to working with DateTime conversion in .NET.

I have a WCF service which has a DateTime property - call it BookingDa

相关标签:
2条回答
  • 2021-01-21 03:51

    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.

    0 讨论(0)
  • 2021-01-21 04:09

    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.

    0 讨论(0)
提交回复
热议问题