I am able to add 102 days to any date I input, but now the problem is, it should be 102 week days (excluding weekends). How can I do that?
Here’s my code for just adding 102 days:
private void txtStartKeyReleased(java.awt.event.KeyEvent evt) {
try {
Date date1 = new SimpleDateFormat("yyyy-MM-dd").parse(txtStart.getText());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
cal.setTime(date1);
cal.add(Calendar.DATE, 102);
String expDateString = sdf.format(cal.getTime());
txtExpiry.setText(expDateString);
} catch (ParseException ex) {
Logger.getLogger(ClientInfo.class.getName()).log(Level.SEVERE, null, ex);
}
}
This should add
weekdaysweek days (weekends are ignored) onto a date. If you pass0forweekdaysit will get the next working day. So,Saturday + 1 weekday = Tuesday.EDIT:
In your code, just replace with the following: