Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Help determining which day a particular date falls on.

1. ## Help determining which day a particular date falls on.

So for this project, we have to calculate which day of the week a particular date falls. For example, given 11/3/2012, you would need to find out on which day March 11th falls. (It goes dd/mm/year).

the ArrayList named Rob contains all the tokenized values of the inputs, which are imported from a text file. (An example input would be 12/4/1992,19/3/1996)

I have calculated whether or not a certain year is a leap year, and I have calculated on which day of the week January 1st falls. I am stuck at the part where I determine the which day of the week a particular date falls when given the information that I have already found.

How would I determine which day of the week a date (such as 20/7/1966) falls?

What do I need to add to the code to make this happen?

PS - Everything up to this point works properly.

```import java.util.*;
import java.io.*;

public class DayOfTheWeek {

private static PrintWriter out;
private static Scanner in;
private static int integer;
private int year;
private static int intDay;
private static int intMonth;
private static int [] temp;
private static int numDays;

public static void main (String [] args) {

int [] monthlength = new int [] {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
boolean leapYear;

try{

FileInputStream fstream = new FileInputStream("input.txt");
// Get the object of DataInputStream

DataInputStream in = new DataInputStream(fstream);
String strLine;

while ((strLine = br.readLine()) != null) {

//split it using /and , as the delimiter

StringTokenizer st = new StringTokenizer(strLine);
st = new StringTokenizer(strLine, "/,");
while (st.hasMoreElements()) {

String token = st.nextToken();
integer = Integer.parseInt(token);
}
}

for (int i = 2; i < rob.size(); i+=3) {

int temp = rob.get(i);
int y = (temp-1);
int x = (36 + y + (y/4) - (y/100) + (y/400)) % 7;
int daysinYear = 365;

if (rob.get(i) % 400 == 0) {
leapYear = true;
daysinYear = (daysinYear + 1);
}

else if ((rob.get(i) %4 == 0) && (rob.get(i) %100 != 0)) {
leapYear = true;
daysinYear = (daysinYear + 1);
}

else {
leapYear = false;

}

if (x == 0) {
System.out.println("January first is a Sunday.");
System.out.println(temp);
}
if (x == 1) {
System.out.println("January first is a Monday.");
System.out.println(temp);
}
if (x == 2) {
System.out.println("January first is a Tuesday.");
System.out.println(temp);
}
if (x == 3) {
System.out.println("January first is a Wendsay.");
System.out.println(temp);
}
if (x == 4) {
System.out.println("January first is a Thursday.");
System.out.println(temp);
}
if (x == 5) {
System.out.println("January first is a Friday.");
System.out.println(temp);
}
if (x == 6) {
System.out.println("January first is a Saturday.");
System.out.println(temp);
}

}

FileWriter output = new FileWriter(args[0]);
PrintWriter out = new PrintWriter(output);

// Write text to file
out.println("This is line 1");
out.println("This is line 2");
out.println("this is line 3 part 2");
out.close();

//Close the input stream
in.close();
}

catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
}```

2. ## Re: Help determining which day a particular date falls on.

Why don't you just use the Calendar class?

If you can't, then think about it this way: how would you do this by hand, without a computer?

3. ## Re: Help determining which day a particular date falls on.

The easiest way would be to first assign a number to each day of the week.(1-7) Then find how many days are in between the current day and the future
date. Then mod by 7. That will give you the day of the week.