This example finds the specified date of an year and a day of a week from calendar.
The Calendar class is an abstract base class
that extends Object class and converts a Date object into a set of integer fields.
Calendar class provides a getInstance() method for
Calendar object whose time fields have been initialized with the current date and
The methods used:
getTime(): This method gets the current time from the calendar.
setTimeInMillis(long millis): This method sets the current time in a calendar object.
getInstance(): This method gets a calendar object containing the default time zone, locale and current time.
The fields used:
DAY_OF_WEEK: This field is used to get and set a day indicating the day of the week. This field takes values SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, and SATURDAY.
DAY_OF_YEAR: This field gets and sets the day to indicate the day number within a current year. e.g. The first day of the year has value 1.
YEAR: This field is used to get and set the year for indicating the year.
The code of the program is given below:
The output of the program is given below:
C:\rajesh\kodejava>java DayOfYearToDayOfWeek Fri Dec 31 16:21:22 GMT+05:30 1999 Weakday: 6
Sun Dec 31 16:21:22 GMT+05:30 2000 Weakday: 1
Mon Dec 31 16:21:55 GMT+05:30 2001 Weekday: 2
Tue Dec 31 16:21:55 GMT+05:30 2002 Weekday: 3
Wed Dec 31 16:21:55 GMT+05:30 2003 Weekday: 4
Liked it! Share this Tutorial