Thursday 15 September 2011

java - Get days between two dates? -



java - Get days between two dates? -

i trying days between 2 values. in format of mmdd.

ex: first date = 0501 sec date = 0519

trying find value of days between 2 dates. in illustration 18. please help me this. tried searching around , can't find solution. give thanks you!

my code have far: getting error: method days in class project3 cannot applied given type.

import java.util.calendar; import java.util.date; import java.util.scanner; public class project3 { public static void main(string[] args) { scanner input = new scanner(system.in); string name = input.next() + input.nextline(); string auto = input.next() + input.nextline(); string key = input.next(); string firstdate = input.next(), lastdate = input.next(); double s = 1.0, c = 1.2, u = 1.4, t = 1.6, b = 2.0; final double n = 89.22, v = (n - 11.4); double daily, total; string daysbetween = project3.days(); } public static long days(date firstdate, date lastdate) { calendar start = calendar.getinstance(); start.settime(firstdate); calendar end = calendar.getinstance(); long daysbetween = 0; while (start.before(end)) { start.add(calendar.day_of_month, 1); daysbetween++; } homecoming daysbetween; } }

this method calculating number of days between 2 dates. keeps rolling day forward, while start date before end date. works regardless of differences in time due daylight saving time.

public static long days(date startdate, date enddate) { calendar start = calendar.getinstance(); start.settime(startdate); calendar end = calendar.getinstance(); long daysbetween = 0; while(start.before(end)) { start.add(calendar.day_of_month, 1); daysbetween++; } homecoming daysbetween; }

java date

No comments:

Post a Comment