As we know that working and non-working (Saturday and Sunday) days can be vary based on month and year. For example in Jan 2016, there are 21 working days and 10 non-working days but in Jan 2017, there are 22 working days and 9 non-working days.
Algorithm :
We are using following steps for writing code.
Get month number and number of days in given month.
Set month number to Calendar class constant MONTH and given year to constant YEAR.
Run the loop until the number of days in given month.
In the loop, set day number to Calendar class constant DAY_OF_MONTH and now this becomes our current date.
Find what is the day on that date using Calendar class constant DAY_OF_WEEK. If its value is 1 or 7 then non-working day otherwise working day.
Repeat step 4, 5 and count working and non-working days.
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, Working and non-working days in Java, Solution in Java, List, ArrayList, String, Regular expressions, switch statement, if else statement, Calendar, Leap year.
About Author:
I am simple guy with lot of ambitions. My main motive is to share whatever knowledge I have related to programming. With me you can easily learn how to solve any programming problem in Java.You can connect with me on social networking sites also.
How to find working and non-working days for given month and year in Java?
Reviewed by Rohit Agarwal
on
1/23/2017
Rating: 5
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.
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.