1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
/* Get Week of month and year using Java Calendar This example shows how to get current week of month and curent week of year using Java Calendar class. */ import java.util.Calendar; public class GetWeekOfMonthAndYear { public static void main(String[] args) { //create Calendar instance Calendar now = Calendar.getInstance(); System.out.println("Current week of month is : " + now.get(Calendar.WEEK_OF_MONTH)); System.out.println("Current week of year is : " + now.get(Calendar.WEEK_OF_YEAR)); now.add(Calendar.WEEK_OF_MONTH, 1); System.out.println("date after one week: " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR)); } } /* Typical output would be Current week of month is : 5 Current week of week is : 52 */ |
can you make me a program that accepts month and display its calendar year?
Minor point, but shouldn’t the output read “date after one week:”? (As opposed to “year”?