Finding the Day of Week/Month/Year or Week Number
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 to specify the field we want to get. If you have a Date object and want to get these values, you could convert the Date object to a Calendar object by using the setTime() method of a Calendar instance and passing in the Date object you want to convert. This is shown in the converting between date and calendar objects phrase earlier in this chapter. |