Difference between System.DateTime and System.DateTimeOffset

Samuel Liew picture Samuel Liew · Jul 1, 2011 · Viewed 7.6k times · Source

Can anyone explain the difference between System.DateTime and System.DateTimeOffset in C#.NET? Which is best suited for building web apps with users from different time zones?

Answer

Samuel Liew picture Samuel Liew · Jul 1, 2011

A DateTime value defines a particular date and time, it includes a Kind property that provides limited information about the time zone to which that date and time belongs.

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.

DateTimeOffset should be considered the default date and time type for application development as the uses for DateTimeOffset values are much more common than those for DateTime values.

See more info, code examples at: http://msdn.microsoft.com/en-us/library/bb384267.aspx