What is difference between a DateTime
and a DateTimeOffset
object?
And when should we use each one?
In a web-application that may change the server's area, storing date and time. Which one is better, or is there any other suggestions?
With its Kind property, DateTime is able to reflect only Coordinated Universal Time (UTC) and the system's local time zone. DateTimeOffset reflects a time's offset from UTC, but it does not reflect the actual time zone to which that offset belongs.
DateTime values lack any knowledge of time zone, or lack thereof. If you need to know when things actually occurred, with more precision than just the approximate date, and you can't be 100% sure that your dates are ALWAYS stored in UTC, then you should consider using DateTimeOffset to represent your datetime values.
The DateTimeOffset structure represents a date and time value, together with an offset that indicates how much that value differs from UTC. Thus, the value always unambiguously identifies a single point in time.
The TimeSpan struct represents a duration of time, whereas DateTime represents a single point in time. Instances of TimeSpan can be expressed in seconds, minutes, hours, or days, and can be either negative or positive.
DateTimeOffset Represents a point in time, typically expressed as a date and time of day, relative to Coordinated Universal Time (UTC) it provides a greater degree of time zone awareness than the DateTime structure. See it here- http://msdn.microsoft.com/en-us/library/bb546101.aspx.
DateTimeOffset Overcomes the drawback of DateTime. It expressed as a date and time of day, relative to Coordinated Universal Time (UTC). For Example:
Given 4/18/2013 11:00:00 AM means absolutely nothing if you don't have a reference point. That could be 11:00:00 AM anywhere in the world. DateTimeOffset contains information about the timezone you are dealing with, which makes all the difference in THE WORLD!
To more details must read once
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With