Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

DateTime vs DateTimeOffset

What is the difference between a DateTime and a DateTimeOffset and when should one be used?


Currently, we have a standard way of dealing with .NET DateTimes in a TimeZone-aware way: Whenever we produce a DateTime we do it in UTC (e.g. using DateTime.UtcNow), and whenever we display one, we convert back from UTC to the user's local time.

That works fine, but I've been reading about DateTimeOffset and how it captures the local and UTC time in the object itself.

Answer*

Cancel
2
  • 1
    A UTC offset does not represent a time zone. A time zone is a complete mapping from "instant in time" to "local time". A DateTimeOffset doesn't tell you the time zone - while it indicates the local time at the represented instant, it does not tell you what the local time will be (say) an hour later. Commented Jan 31 at 8:34
  • Thank you for clarifying. That added more depth in my understanding of DataTimeOffset. Commented Feb 3 at 11:05