How to add N working days to the current date in Java?
Problem Description :
Write a program in Java that adds N working days to the current date and prints new date.
Add n working days in current date |
Concept :
There are 5 working days per week (Monday, Tuesday, Wednesday, Thursday, Friday). Here in a loop we are adding 1 to the current date and checking day of that date. If it is Sunday or Saturday then we are doing increment to the value of N because we are interested in working days.
- We need to do addition to current date using add() method of Calendar class that accepts DAY_OF_MONTH constant and number of days that you want to add.
- For getting day, we need to use DAY_OF_WEEK constant of Calendar class.
Recommended :
Java program :
Output :
Output - How to add N working days to the current date in Java? |
Similar Problem :
How to add N working days to the given date in Java?
Solution - This is very simple first of all Convert given String to Date and rest is same as above.
References :
Thank you friends, I hope you have clearly understood the solution of this problem. If you have any doubt, suggestion or query please feel free to comment below. You can also discuss this solution in our forum.
Tags : Date and Time problems, Addition of n working days in Java, Solution in Java, if else statement, for loop, Calendar.
How to add N working days to the current date in Java?
Reviewed by Rohit Agarwal
on
1/10/2017
Rating:
No comments:
Please provide your valuable comments. If you have any suggestion please share with me I will work on it and if you have any question or doubt please ask, don't hesitate. I am your friend, i will clarify all your doubts.