Wednesday, December 16, 2009


I was looking for an efficient date time processing in java, as I believe that there is a bit of a hitch in java's date time design (the Calendar class..) as it lacks some of the simple and basic methods for the date processing which is developer friendly.

Thanks to the project Joda Time (led by Stephen Colebourne) which is a developer friendly alternative to the JAVA's date and time API.
Here is a very basic example using the Joda time and the Calendar API.

To calculate the current year using the Calendar API :

Calendar today = Calendar.getInstance();
int year = today.get( Calendar.YEAR );

But in Joda time :

DateTime today = new DateTime();
int year = today.getYear();

For more refer ......

No comments:

Post a Comment