"Time" for a change in Java
I have been an enterprise developer for a few years now and I started in c# back in the .NET 1.0/1.1 days. From the get-go, I found c# to be a great language and have been following its progress for some time, and will continue to do so for even longer.
At the moment I’m in the Java world and although the .NET vs Java world are very different in so many ways, one thing that has always annoyed me about Java was the way it handles its date and time functionality.
I was always looking up the best way to calculating 2 dates together, or swiftly converting a string to a date, etc… and found that it really wasn’t as simple as it should be, and coming from the .NET world, where there are very simple date constructs, this really really surprised and annoyed me.
Then I heard about Joda Time the simple Java replacement for the Java calendar classes.
Let me just say that my worries are over, this date framework allows me to use dates the way I would expect them to work.
like so:
public Days daysToNewYear(LocalDate fromDate) {
LocalDate newYear = fromDate.plusYears(1).withDayOfYear(1);
return Days.daysBetween(fromDate, newYear);
}
(This was taken directly from the homepage as a simple example).
“Days.daysBetween(from ,to)“
what a simple example of how dates should be implemented. I love it.
I will be pushing to use this library/framework from now on in my projects.
About Me
Chesung Subba
Author/Writer
Hello, I'm Chesung Subba, a passionate writer who loves sharing ideas, stories, and experiences to inspire, inform, and connect with readers through meaningful content.
Follow Me
Connect with me and be part of my social media community.
Leave a Reply