Rosetta Code:Add a Task: Difference between revisions
Content added Content deleted
(→Create the page: we can get any last day(monday,tuesday,...sunday) on every month for specific year range.) |
|||
Line 12: | Line 12: | ||
we can get any last day(monday,tuesday,...sunday) on every month for specific year range. |
we can get any last day(monday,tuesday,...sunday) on every month for specific year range. |
||
public class LastSunday { |
|||
/** |
|||
* Venkata Janga |
|||
* @param args |
|||
*/ |
|||
public static void main(String[] args) { |
|||
int year = 2015; |
|||
GregorianCalendar calander = new GregorianCalendar(year, 0, 1); |
|||
for (String mon : new DateFormatSymbols(Locale.US).getShortMonths()) { |
|||
if (!mon.isEmpty()) { |
|||
int totalDaysOfMonth = calander.getActualMaximum(Calendar.DAY_OF_MONTH); |
|||
calander.set(Calendar.DAY_OF_MONTH, totalDaysOfMonth); |
|||
/** |
|||
* 1--> FRIDAY |
|||
* 2--> THURSDAY |
|||
* 3--> WEDNES DAY |
|||
* 4--> TUESDAY |
|||
* 5--> MONAY |
|||
* 6--> SUNDAY |
|||
* 7--> SATURADAY |
|||
* */ |
|||
int daysToRollBack = (calander.get(Calendar.DAY_OF_WEEK) + 6) % 7; |
|||
int day = totalDaysOfMonth - daysToRollBack; |
|||
calander.set(Calendar.DAY_OF_MONTH, day); |
|||
System.out.printf("%d %s %d\n", year, mon, day); |
|||
calander.set(year,calander.get(Calendar.MONTH) + 1, 1); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
===Draft vs non-draft=== |
===Draft vs non-draft=== |