datetime - Find the difference between two dates (Inclusive of start and end date) in Java -


this question has answer here:

i need find difference between 2 dates in java , difference should inclusive of start , end date. tried using below piece of code not including start , end date.

long diffdays = days.daysbetween(new datetime(startdate), new datetime(enddate)).getdays(); 

is there utility method achieve this?

if you're not using library 1 of method:

public static map<timeunit,long> computediff(date date1, date date2) {     long diffinmillies = date2.gettime() - date1.gettime();     list<timeunit> units = new arraylist<timeunit>(enumset.allof(timeunit.class));     collections.reverse(units);     map<timeunit,long> result = new linkedhashmap<timeunit,long>();     long milliesrest = diffinmillies;     ( timeunit unit : units ) {         long diff = unit.convert(milliesrest,timeunit.milliseconds);         long diffinmilliesforunit = unit.tomillis(diff);         milliesrest = milliesrest - diffinmilliesforunit;         result.put(unit,diff);     }     return result; } 

or else use joda


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -