Find Day of Month

This example explores how to find the day of a month and the day of a week

Find Day of Month


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:
This method is used to get current time from calendar.
This method gets a calendar using the default time zone , locale and current time.

The fields used:
This field is used to get and set the week indicating the week number within the current month.
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:

import java.util.Calendar;
public class DayYearToDayMonth 
  public static void main(String[] args)
  Calendar calendar = Calendar.getInstance();
  calendar.set(Calendar.YEAR, 2007);
  calendar.set(Calendar.DAY_OF_YEAR, 181);
  System.out.println("\nThe date of Calendar is: " +
  int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);  
  System.out.println("The day of month: " +
  int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
  System.out.println("The day of week: " 

The output of the program is given below:

C:\rajesh\kodejava>java DayYearToDayMonth
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

Download this example.

Share on Google+Share on Google+

Find Day of Month

Posted on: July 6, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Find Day of Month  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
Ivon Sumana-Ang
August 17, 2011
coding time

so glad to gst it
Simon Greenaway
May 12, 2012
Better method

int dom=Integer.parseInt(new SimpleDateFormat("MM").format(new Date())); int dow=Integer.parseInt(new SimpleDateFormat("dd").format(new Date()));
Deepak Tiwari
October 4, 2012
to discuss any topic for java

hi sir