I am working with Java to get the number of days between two dates. When I say the application date 27, it shows 0, and when I give 26, it also shows 0. Is there anything wrong with my code? Any thoughts would be greatly appreciated.
This is my code
public static zero main (string [] args) java.lang.Exception throws {DateFormat dateFormat = New SimpleDateFormat ("YA-MM-DD Hh: mm: ss "); Date currentDate = new date (); System.out.println ("Current Date:" + dateFormat.format (currentDate)); SimpleDateFormat formatter = New Simple Format ("yyyy-MM-dd HH: mm: ss"); String Strapped = "2014-10-28 15: 11: 30.0"; DateEpadata = Formater Pars (strapped); System.out.println ("Application date:" + formatter.format); Long diff = appDate.getTime () - currentDate.getTime (); Long diffDays = diff / (24 * 60 * 60 * 1000); System.out.println ("Diff Days:" + diffDays); }
You can try this way using
long duration = app date .getTime () - currentDate.getTime (); Prolonged diffInSeconds = TimeUnit.MILLISECONDS.to seconds (duration); Prolonged diffInMinutes = TimeUnit.MILLISECONDS.toMinutes (duration); Long time different time = time unite. MILILESCNSSHORS (period); Prolonged diffInDays = TimeUnit.MILLISECONDS.toDays (period); // day number
Comments
Post a Comment