Public static void main (String[] args) {datediff ("2015-04-01 17:06:49", " 2015-04-02 17:06:50 "," Yyyy-mm-dd hh:mm:ss ");} Public static void datediff (string starttime, string endtime, string Format) {// generate a Simpledateformate object in the incoming format simpledateformat sd = new SimpleDateFormat (format);long nd = 1000 * 24 * 60 * 60;// The number of milliseconds in a day long nh = 1000 * 60 * 60;// the number of milliseconds in an hour long nm = 1000 * 60;// the number of milliseconds in a minute long ns = 1000;// milliseconds in a second long diff;try {// Get a millisecond time difference of two time try {long diff = sd.parse (EndTime). GetTime ()- sd.parse (startTime). GetTime ();long day = diff / nd;// Calculate the difference in how many days long hour = diff % nd / nh;// How many hours to calculate the difference long min = diff % nd % nh / nm;// Calculate the difference in how many minutes long sec = diff % nd % nh % nm / ns;// calculate the difference in seconds//output result System.out.println ("Time difference:" + day + "Day" + hour + "Hours" + min + "minutes" + sec + "seconds. ");} catch (parseexception e) {// TODO Auto-generated catch Blocke.printstacktrace ();}}
How many days does Android compute differ