Macca Blog

My life experiences with code and design

"Time" for a change in Java

Posted on by Mark

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.

This entry was posted in Calendar, Date, Java, Joda. Bookmark the permalink.

Leave a Comment

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>