Monday, April 26, 2010

Why Joda Time ?

They said :  Joda-Time has been created to radically change date and time handling in Java. The JDK classes Date and Calendar are very badly designed, have had numerous bugs and have odd performance effects. Here are some of our reasons for developing and using Joda-Time

joda time


public boolean isAfterPayDay (DateTime datetime) {
if (datetime.getMonthOfYear () == 2) { // February is month 2!!
return datetime.getDayOfMonth () > 26;
}
return datetime.getDayOfMonth () > 28;
}

public Days daysToNewYear (LocalDate fromDate) {
LocalDate newYear = fromDate.plusYears (1).withDayOfYear (1);
return Days.daysBetween (fromDate, newYear);
}

public boolean isRentalOverdue (DateTime datetimeRented) {
Period rentalPeriod = new Period ().withDays (2).withHours (12);
return datetimeRented.plus (rentalPeriod).isBeforeNow ();
}

public String getBirthMonthText (LocalDate dateOfBirth) {
return dateOfBirth.monthOfYear ().getAsText (Locale.ENGLISH);
}

No comments:

Post a Comment