I get a date and want to check if it is the next sunday.I found alot of code with Calendar etc, but I can't find the right code. And I don't really understand how I can know if it is the next sunday from a date.
Thanks for you help
I get a date and want to check if it is the next sunday.I found alot of code with Calendar etc, but I can't find the right code. And I don't really understand how I can know if it is the next sunday from a date.
Thanks for you help
Break the problem down:
new Date();
First of, I recommend Joda Time as a much better Date/Time API than Calendar
.
As for your processing it breaks down into easy steps:
DateTime
objects for the two datesthis might be helpful to you , you can chek by dayOfWeek == Calendar.SUNDAY after adding one day
With Lamma Date it's very easy to first obtain next Sunday, then we can use equals
check if the date is next Sunday.
Date today = new Date(2014, 7, 1); // assume today is 2014-07-01
Date nextSunday = today.next(DayOfWeek.SUNDAY); // 2014-07-06