In today’s newsletter we are going to discuss
What is Noda Time
Why we should use it over default Date Time
How to use it in .NET
What is Noda Time
Noda Time is a Nuget Package / Library developed by Jon Skeet with 96M downloads (until today), it is an alternative for dealing with date and time. If you are familiar with Java world then Noda Time is C# version of Joda Time
Why we should use it over default Date Time
Lack of clarity in
DateTime
especially when comparing local and UTC timesDateTimeKind
property and various operations likeToUniversalTime()
andToLocalTime()
can lead to unexpected resultsDateTime
does not provide a comprehensive solution for handling time zones.TimeZoneInfo
, used in .NET, relies on Windows time zone IDs, which may differ from widely used Olson (tz) identifiersUnfortunately humanity did’ not agree on single calendar (Gregorian, Julian, Coptic and Buddhist) , NodaTime covers this space which default lacks.
Instead of maintaining
offset
in default Noda gives you facility of usingZonedDateTime
I love their documentation , I have not seen such an amazing documentation yet. They really care and understand the needs of users
If I could not satisfy you then Mr. Jon Skeet will hopefully, Read this blog of Jon Skeet for in depth
How to use it in .NET
It is quite simple , you just need to install these Nuget packages
NodaTime
NodaTime.Testing
NodaTime.Serialization.JsonNet
These are few types available in .NET with NodaTime
LocalDate
including day,month,year , calendarDateTimeZone
- To shift in a specific time zone , pass it IanaZonedClock
- A clock associated with time zonePeriod
- To calculate time difference in calendrical termsDuration -
Fixed length of elapsed time (irrespective of calendar)Instant
- A instant on global timeline with nanosecond resolution
It is difficult to include all of them in this post , better visit documentation of NodaTime
Jon was born on June 19th, 1976 (Gregorian). How old is he now, in the UK time zone?
The more you explore it more interesting things you will find.
Whenever you’re ready , there are 3 ways I can help you
Promote yourself to 3550+ subscribers by sponsoring my Newsletter (Reach me at mwaseemzakir@gmail.com)
Become a Patron and get access to 120+ .NET Questions and Answers , I add 2-5 new questions every week
Get my FREE eBook from Gumroad that contains 30 .NET Tips (Downloaded by 2300+ and 100+ five star ratings)
Special Offers 📢
Ultimate ASP.NET Core Web API Second Edition - Premium Package
10% off with discount code: 9s6nuez