Wednesday, July 16, 2008

Knowing that the Calendar object is today or not, in java

When programming in java sometimes you may come a cross to situations that you have a Date or Calendar object and you want to check that object represent today or not. So here is a solution for that. I ope that you know how to convert a Date to Calendar...

public static boolean isSameDate(Calendar date) {
Calendar now = Calendar.getInstance();
return date.get(Calendar.YEAR) == now.get(Calendar.YEAR)
&& date.get(Calendar.MONTH) == now.get(Calendar.MONTH)
&& date.get(Calendar.DATE) == now.get(Calendar.DATE);

~ Vidula Hasaranga - විදුල හසරංග ~

Post a Comment