Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between 'DateTime' and 'DateTimeOffset' [duplicate]

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?

like image 575
amiry jd Avatar asked Jan 31 '12 01:01

amiry jd


People also ask

What's the difference between DateTime and DateTimeOffset?

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.

Should you always use DateTimeOffset?

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.

What does DateTimeOffset mean?

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.

What is the difference between DateTime and TimeSpan?

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.


2 Answers

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.

like image 86
DotNetUser Avatar answered Sep 21 '22 18:09

DotNetUser


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

like image 39
Ajay Sharma Avatar answered Sep 25 '22 18:09

Ajay Sharma