By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,538 Members | 1,130 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,538 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
ch******************@yahoo.co.in wrote:
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 .


get(Calendar.DAY_OF_WEEK)

http://java.sun.com/j2se/1.4.2/docs/api/

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.
Jul 17 '05 #2

P: n/a
package samples;

import java.util.*;

/**
* <p>Title: Sample2DMonths</p>
* <p>Description: 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 [] getMonthsoftheYear(int year) {
int [] results = new int[12];
for (int i=0; i<results.length; i++) {
Calendar month = new GregorianCalendar(year, i, 1);
results[i] = month.getActualMaximum(Calendar.DAY_OF_MONTH);
}
return results;
}

public void printMonths() {
System.out.println("For the year "+year);
for (int i=0; i<daysInMonth.length; i++)
System.out.println("Days in month "+i+" = "+daysInMonth[i]);
}

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

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

year1999.printMonths();
leapYear.printMonths();

}

}

Stewart Gordon wrote:
ch******************@yahoo.co.in wrote:
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 .

get(Calendar.DAY_OF_WEEK)

http://java.sun.com/j2se/1.4.2/docs/api/

Stewart.


Jul 17 '05 #3

P: n/a
package samples;

import java.util.*;

/**
* <p>Title: Sample2DMonths</p>
* <p>Description: 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 calcMonthsoftheYear(int year) {
this.months = new GregorianCalendar[12];
for (int i=0; i<months.length; i++)
this.months[i] = new GregorianCalendar(year, i, 1);
}

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

months[i].getActualMaximum(Calendar.DAY_OF_MONTH));
System.out.println("\tFirst of the month starts on a " +
days[months[i].get(Calendar.DAY_OF_WEEK)]);
}
}

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

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

year1999.printMonths();
leapYear.printMonths();

}

}

perry wrote:
package samples;

import java.util.*;

/**
* <p>Title: Sample2DMonths</p>
* <p>Description: 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 [] getMonthsoftheYear(int year) {
int [] results = new int[12];
for (int i=0; i<results.length; i++) {
Calendar month = new GregorianCalendar(year, i, 1);
results[i] = month.getActualMaximum(Calendar.DAY_OF_MONTH);
}
return results;
}

public void printMonths() {
System.out.println("For the year "+year);
for (int i=0; i<daysInMonth.length; i++)
System.out.println("Days in month "+i+" = "+daysInMonth[i]);
}

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

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

year1999.printMonths();
leapYear.printMonths();

}

}

Stewart Gordon wrote:
ch******************@yahoo.co.in wrote:
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 .


get(Calendar.DAY_OF_WEEK)

http://java.sun.com/j2se/1.4.2/docs/api/

Stewart.


Jul 17 '05 #4

P: n/a
My reading of the manual found this:
Calendar.get(Calendar.DAY_OF_WEEK);
Take a look at the Calendar API...
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


--
Composed with Newz Crawler 1.5 http://www.newzcrawler.com/
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.