java - Javafx Using Date Picker -
i creating java fx application using scene builder. have 2 date pickers date1 , date two. need count number of days between date1 , date2 excluding sunday. have searched various answers none caters.
any appreciated.
the following should work.
long date1 = datepicker1.getvalue().toepochday(); long date2 = datepicker2.getvalue().toepochday(); int days = (int) math.abs(date1 - date2); example:
long date1 = 16322; // 09/09/2014 long date2 = 16329; // 09/16/2014 int days = (int) math.abs(date1 - date2); system.out.println(days); // 7 days note: not think jfx2.0 has built-in datepicker, assuming using jdk8.
also, pulled the datepicker.getvalue().toepochday() logic question:
stack overflow: value date picker; deals jfx8.
the epoch in localdate.toepochday() number of days since 01/01/1970.
extra credit
to answer question comment below, following.
int days = daysbetween( datepicker1.getvalue(), datepicker2.getvalue(), arrays.aslist(dayofweek.sunday) ); public static int daysbetween(localdate start, localdate end, list<dayofweek> ignore) { int count = 0; localdate curr = start.plusdays(0); // create copy. while (curr.isbefore(end)) { if (!ignore.contains(curr.getdayofweek())) count++; curr = curr.plusdays(1); // increment day. } return count; }
Comments
Post a Comment