O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Finding the Day of Week/Month/Year or Week Number

Calendar cal = Calendar.getInstance();
											System.out.println("Day of week: " +
											cal.get(Calendar.DAY_OF_WEEK));
											System.out.println("Month: " +
											cal.get(Calendar.MONTH));
											System.out.println("Year: " +
											cal.get(Calendar.YEAR));
											System.out.println("Week number: " +
											cal.get(Calendar.WEEK_OF_YEAR));

You can easily determine values such as the day of the week, the month, the year, the week number, and more using the Calendar object’s get() method. In this phrase, we get a Calendar object representing the current date and time using the getInstance() method. We then print out the day of the week, the month, the year, and the week of the year by using the get() method and passing the appropriate Calendar constant ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required