C#: Default to DateTimeOffset over DateTime
Date: 2020-11-30 | csharp | date | time |
DISCLOSURE: If you buy through affiliate links, I may earn a small commission. (disclosures)
Note to self: Default to using DateTimeOffset for dates rather than DateTime.
DateTimeOffset
- Date and time
- Offset indicating difference from UTC
Is basically DateTime plus it has awareness of time zones.
DateTime
- Date and time
Conclusion
DateTimeOffset is typically what I'll want to use. It does everything DateTime does plus has some additional data on time zones. This makes it easier to do date arithmetic after the fact if time zones need to be taken into account.
References
Want more like this?
The best way to support my work is to like / comment / share for the algorithm and subscribe for future updates.