1, Calendar to determine whether the same day code is as follows :
Idea: The time format of two date types into the calendar type is compared to the date of two events
public static Boolean issameday (date date1, date date2) {
Calendar Caldatea = Calendar.getinstance ();
Caldatea.settime (date1);
Calendar caldateb = Calendar.getinstance ();
Caldateb.settime (date2);
Return Caldatea.get (calendar.year) = = Caldateb.get (calendar.year)
&& caldatea.get (calendar.month) = = Caldateb.get (calendar.month)
&& caldatea.get (calendar.day_of_month) = = Caldateb
. Get (Calendar.day _of_month);
}
2, Calendar calculation current time known current date
public static String getyearandmonthday (int dayofmonth) {
Calendar rightnow = Calendar.getinstance ();
Date today = new Date (System.currenttimemillis ());
Rightnow.settime (today);
Rightnow.add (Calendar.month, 1); Righthow.add (calendar.month,1) return
(Rightnow.get (calendar.year) + "year" +rightnow.get (calendar.month)) + "Month" + DayOfMonth + "Day";
}
3, calendar calculation One months after the Today
public static String getnextdate (int dayofmonth) {
Calendar rightnow = Calendar.getinstance ();
Date today = new Date (System.currenttimemillis ());
Rightnow.settime (today);
int day = Rightnow.get (calendar.day_of_month+1);
Return Rightnow.get (calendar.year) + "-" + (Rightnow.get (calendar.month) + 2) + "-" + DayOfMonth;
}
4, two time difference how much
public static final int Getdayfromtimediff (date d1, date D2) {
if (D1 = = NULL | | d2 = NULL) {return
0;
}
long L1 = D1.gettime ();
Long L2 = D2.gettime ();
Long diff = l2-l1;
int day = (int) (diff/(1000 * 3600 *));
return day;
}