When Would You Prefer DateTime Over DateTimeOffset

A few months ago I was introduced to the new DateTimeOffset type and was glad DateTime 's flaws with regard to time zones were finally taken care of.

However, I was left wondering if there were any overhead or problems that could occur from using this new type.

I work on a multi-locale web application. Does anyone know of anything that could sway me from just using it for all my date/time work? Is there a window for abuse here?

Reference: DateTimeOffset: A New DateTime Structure in .NET 3.5 by Justin Van Patten


Sometimes you really just want to represent a "local" (timezone unaware) date and time rather than an instant in time. To be honest it's more often useful to represent just a time - eg "wake me up at 8am, regardless of timezone" - but date and time could be useful too.

I agree that for the vast majority of cases, DateTimeOffset is a better fit. It does strike me as odd that there isn't a DateTimeTimeZone struct which has both the instant and its timezone though... an offset doesn't actually give you all the information you need. (For instance, given a DateTimeOffset , you don't know what the time will be 24 hours later, because you don't know when DST might kick in.)

If you want that kind of structure, I have a very crude implementation in another answer. I'm sure it could be improved very easily :)


那么,一个明显的答案就是当你需要支持没有装入SP的客户端时(它实际上并不在3.5中 - 它是在2.0 SP1中同时发货的)。

链接地址: http://www.djcxy.com/p/46554.html

上一篇: 存储DateTime(UTC)与存储DateTimeOffset

下一篇: 什么时候你会比DateTimeOffset更喜欢DateTime?