DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT); String startdate = dateFormat.format(new Date()); String = enddate; I want to find out the number of days between these two dates,but these two dates are in String format. How can i do that?
One way to do it, as long as your dates are both after 1/1/1970, is to convert your strings to Date objects, using either DateFormat or SimpleDateFormat like Miguel did. Then use the getTime() method on those dates to get their values in milliseconds. Subtract the two, then divide the result by 86400000 (milliseconds in a day).
Joined: Feb 08, 2004
Wouldn't that only work as long as the two dates are in the same year?
that's what i had in mind, but you'r absolutely right!
Joined: Apr 08, 2004
Try this code, i am not getting the exact difference....It shows difference between Apr 3 and Apr 4th value is 0. (instead of 1)