This example explores how to find the day of a month and the day of a week This example sets the year as 2007 and the day as 181. The example finds the day of a month and the day of a week by using get(field_name) method.
The Calendar class extends Object class. It is an abstract base class and converts a Date object into a set of integer fields. Calendar class provides a getInstance() method that returns a Calendar object whose time fields are initialized with the current date and time.
The methods used:
getTime(): This method is used to get current time from calendar.
getInstance(): This method gets a calendar using the default time zone , locale and current time.
The fields used:
WEEK_OF_MONTH: This field is used to get and set the week indicating the week number within the current month.
DAY_OF_WEEK: This field gets and set the day indicating the day of the week. This field takes values SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, and SATURDAY.
The code of the program is given below:
The output of the program is given below:
The date of Calendar is: Sat Jun 30 17:03:01 GMT+05:30 2007 The day of month: 30 The day of week: 7
Rs. 20,000 US$ 300
Today: Rs. 10,000 US$150
Course Duration: 30 hrs
Posted on: July 6, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles