how to to find which day of the week using Calendar class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • chennakeshava_ramesh@yahoo.co.in

    how to to find which day of the week using Calendar class

    hi,

    I have a problem, I am not able to find out which day of the week it
    is using the calendar class.
    I am using set() function to set the date
    and want to find out which day i.e mon,tue etc of the week it is .

    Can anyone help me out with this,

    regards
    RAMESH
  • Stewart Gordon

    #2
    Re: how to to find which day of the week using Calendar class

    chennakeshava_r amesh@yahoo.co. in wrote:
    [color=blue]
    > hi,
    >
    > I have a problem, I am not able to find out which day of the week it
    > is using the calendar class.
    > I am using set() function to set the date
    > and want to find out which day i.e mon,tue etc of the week it is .[/color]

    get(Calendar.DA Y_OF_WEEK)



    Stewart.

    --
    My e-mail is valid but not my primary mailbox, aside from its being the
    unfortunate victim of intensive mail-bombing at the moment. Please keep
    replies on the 'group where everyone may benefit.

    Comment

    • perry

      #3
      Re: how to to find which day of the week using Calendar class

      package samples;

      import java.util.*;

      /**
      * <p>Title: Sample2DMonths</p>
      * <p>Descriptio n: Just a example 2D array </p>
      * <p>Copyright: Perry Anderson</p>
      * @author Perry Anderson
      * @version 1.0
      */

      public class Sample2DMonths {

      int year;
      int [] daysInMonth;

      public int [] getMonthsoftheY ear(int year) {
      int [] results = new int[12];
      for (int i=0; i<results.lengt h; i++) {
      Calendar month = new GregorianCalend ar(year, i, 1);
      results[i] = month.getActual Maximum(Calenda r.DAY_OF_MONTH) ;
      }
      return results;
      }

      public void printMonths() {
      System.out.prin tln("For the year "+year);
      for (int i=0; i<daysInMonth.l ength; i++)
      System.out.prin tln("Days in month "+i+" = "+daysInMon th[i]);
      }

      public Sample2DMonths( int year) {
      daysInMonth = getMonthsoftheY ear(year);
      this.year = year;
      }

      public static void main(String[] args) {
      Sample2DMonths year1999 = new Sample2DMonths( 1999);
      Sample2DMonths leapYear = new Sample2DMonths( 2000);

      year1999.printM onths();
      leapYear.printM onths();

      }

      }



      Stewart Gordon wrote:[color=blue]
      > chennakeshava_r amesh@yahoo.co. in wrote:
      >[color=green]
      >> hi,
      >>
      >> I have a problem, I am not able to find out which day of the week it
      >> is using the calendar class.
      >> I am using set() function to set the date and want to find out which
      >> day i.e mon,tue etc of the week it is .[/color]
      >
      >
      > get(Calendar.DA Y_OF_WEEK)
      >
      > http://java.sun.com/j2se/1.4.2/docs/api/
      >
      > Stewart.
      >[/color]

      Comment

      • perry

        #4
        Re: how to to find which day of the week using Calendar class

        package samples;

        import java.util.*;

        /**
        * <p>Title: Sample2DMonths</p>
        * <p>Descriptio n: Just a example 2D array </p>
        * <p>Copyright: Perry Anderson</p>
        * @author Perry Anderson
        * @version 1.0
        */

        public class Sample2DMonths {

        int year;
        Calendar [] months;
        String days[] = { "Unknown", "Sunday", "Monday", "Tuesday", "Wednesday" ,
        "Thursday", "Friday", "Saturday" };

        private void calcMonthsofthe Year(int year) {
        this.months = new GregorianCalend ar[12];
        for (int i=0; i<months.length ; i++)
        this.months[i] = new GregorianCalend ar(year, i, 1);
        }

        public void printMonths() {
        System.out.prin tln("For the year "+year);
        for (int i=0; i<months.length ; i++) {
        System.out.prin t("Days in month " + i + " = " +

        months[i].getActualMaxim um(Calendar.DAY _OF_MONTH));
        System.out.prin tln("\tFirst of the month starts on a " +
        days[months[i].get(Calendar.D AY_OF_WEEK)]);
        }
        }

        public Sample2DMonths( int year) {
        calcMonthsofthe Year(year);
        this.year = year;
        }

        public static void main(String[] args) {
        Sample2DMonths year1999 = new Sample2DMonths( 1999);
        Sample2DMonths leapYear = new Sample2DMonths( 2000);

        year1999.printM onths();
        leapYear.printM onths();

        }

        }

        perry wrote:[color=blue]
        > package samples;
        >
        > import java.util.*;
        >
        > /**
        > * <p>Title: Sample2DMonths</p>
        > * <p>Descriptio n: Just a example 2D array </p>
        > * <p>Copyright: Perry Anderson</p>
        > * @author Perry Anderson
        > * @version 1.0
        > */
        >
        > public class Sample2DMonths {
        >
        > int year;
        > int [] daysInMonth;
        >
        > public int [] getMonthsoftheY ear(int year) {
        > int [] results = new int[12];
        > for (int i=0; i<results.lengt h; i++) {
        > Calendar month = new GregorianCalend ar(year, i, 1);
        > results[i] = month.getActual Maximum(Calenda r.DAY_OF_MONTH) ;
        > }
        > return results;
        > }
        >
        > public void printMonths() {
        > System.out.prin tln("For the year "+year);
        > for (int i=0; i<daysInMonth.l ength; i++)
        > System.out.prin tln("Days in month "+i+" = "+daysInMon th[i]);
        > }
        >
        > public Sample2DMonths( int year) {
        > daysInMonth = getMonthsoftheY ear(year);
        > this.year = year;
        > }
        >
        > public static void main(String[] args) {
        > Sample2DMonths year1999 = new Sample2DMonths( 1999);
        > Sample2DMonths leapYear = new Sample2DMonths( 2000);
        >
        > year1999.printM onths();
        > leapYear.printM onths();
        >
        > }
        >
        > }
        >
        >
        >
        > Stewart Gordon wrote:
        >[color=green]
        >> chennakeshava_r amesh@yahoo.co. in wrote:
        >>[color=darkred]
        >>> hi,
        >>>
        >>> I have a problem, I am not able to find out which day of the week it
        >>> is using the calendar class.
        >>> I am using set() function to set the date and want to find out which
        >>> day i.e mon,tue etc of the week it is .[/color]
        >>
        >>
        >>
        >> get(Calendar.DA Y_OF_WEEK)
        >>
        >> http://java.sun.com/j2se/1.4.2/docs/api/
        >>
        >> Stewart.
        >>[/color]
        >[/color]

        Comment

        • Steve

          #5
          Re: how to to find which day of the week using Calendar class

          My reading of the manual found this:
          Calendar.get(Ca lendar.DAY_OF_W EEK);
          Take a look at the Calendar API...[color=blue]
          > hi,
          >
          > I have a problem, I am not able to find out which day of the week it
          > is using the calendar class.
          > I am using set() function to set the date
          > and want to find out which day i.e mon,tue etc of the week it is .
          >
          > Can anyone help me out with this,
          >
          > regards
          > RAMESH[/color]

          --
          Composed with Newz Crawler 1.5 http://www.newzcrawler.com/

          Comment

          Working...