473,324 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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
Jul 17 '05 #1
4 5704
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: cg_news | last post by:
I understand that the GregorianCalendar can be used to calculate the week of year for a date, and after instantiating a GregorianCalendar object with the no arg constructor, I can infact retrieve...
1
by: JH | last post by:
Why there is not full week support in DateTime classes in .NET. For instance windows`s normal calendar control knows how to show week numbers, but you can`t ask that from DateTime class. Also...
2
by: Steph. | last post by:
Hi, When I use the "Calendar.GetWeekOfYear" function (with "fr-BE" as CultureInfo and Monday as the first day of week) I get : Friday 31/12/2004 : week = 53
7
by: Shuffs | last post by:
Could someone, anyone please tell me what I need to amend, to get this function to take Sunday as the first day of the week? I amended the Weekday parts to vbSunday (in my code, not the code...
14
by: deko | last post by:
This runs, but does not narrow to current week. suggestions appreciated! SELECT lngEid, dtmApptDate, Subject, Appt_ID FROM qry002 WHERE (dtmApptDate BETWEEN DateAdd("d",-weekday()+2,) And...
10
by: Ty Smith via AccessMonster.com | last post by:
I noticed that the week numbers in Stephan Leban's MonthCalendar are not consistent with Microsoft Outlook (they are shifted one week forward). Is there any way I can sync these two up by changing...
3
by: | last post by:
Hi!! Did Infragistics or some other company else provide a web calendar conrol with the features and look of Microsoft Outlook calendar? I mean that feature that you can choose Day / Work Week /...
10
by: purkka | last post by:
Hi I did not find any solution from Internet how to do it. There is a lot of samples how to retrieve day of the week, but not number of the week. With rgds MP
9
by: Joe Kovac | last post by:
Hi! Our customer wants to see his data week by week. So, how could I let him select a week the most easy way? Anyone already solved this challenge? Proposal (1): Use a calendar to select the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.