Here you can find the source of getDateDiffDay(String begindate, String enddate)
public static long getDateDiffDay(String begindate, String enddate)
//package com.java2s; //License from project: Apache License import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.Date; import java.util.GregorianCalendar; public class Main { public static long getDateDiffDay(String begindate, String enddate) { long hourDiff = getDateDiffHour(begindate, enddate); Float dayDiff = (float) (hourDiff / 24); return dayDiff.intValue(); }/*from ww w. ja va2s . c o m*/ public static long getDateDiffDay(String begindate) { GregorianCalendar thisday = new GregorianCalendar(); SimpleDateFormat shortFormatter = new SimpleDateFormat("yyyy-MM-dd"); String thisdateStr = shortFormatter.format(thisday.getTime()); return getDateDiffDay(begindate, thisdateStr); } public static long getDateDiffHour(String begindate, String enddate) { long minuteDiff = getDateDiffMinute(begindate, enddate); Float hourDiff = (float) (minuteDiff / 60); return hourDiff.intValue(); } public static long getDateDiffMinute(String begindate, String enddate) { SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd kk:mm:ss"); ParsePosition pos1 = new ParsePosition(0); ParsePosition pos2 = new ParsePosition(0); if (begindate.length() == 10) begindate = begindate + " 00:00:00"; if (enddate.length() == 10) enddate = enddate + " 00:00:00"; Date BeginDate = formatter.parse(begindate, pos1); Date EndDate = formatter.parse(enddate, pos2); long dateDiff = EndDate.getTime() - BeginDate.getTime(); Float minuteDiff = (float) (dateDiff / 1000 / 60); return minuteDiff.intValue(); } }