Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions? | Software Development
 

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:
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:

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: " +
 calendar.getTime
());
        int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);  
        System.out.println("The day of month: " +
 dayOfMonth
);  
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
    System.out.println("The day of week: " 
dayOfWeek
);
    }
}

The output of the program is given below:

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

                         

» View all related tutorials
Related Tags: c com class date comparison io methods method dates using equals this for ssi e iso section not ls first

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
 
Tell A Friend
Your Friend Name

 

 
Recently Viewed
Software Solutions
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.