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 - විදුල හසරංග ~
No comments:
Post a Comment