import java.io.*;
import java.util.*;
import java.util.Date;
import java.util.Calendar;
public class Test2
{
public static void main(String args[]) throws Exception
{
Date date=new Date("2001/9/31");
System.out.println(date.getDay());
}
}
Returns the day of the week represented by this date. The returned value (0 = Sunday, 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday) represents the day of the week that contains or begins with the instant in time represented by this Date object, as interpreted in the local time zone.
import java.util.*;
import java.util.Date;
import java.util.Calendar;
public class Test2
{
public static void main(String args[]) throws Exception
{
Date date=new Date("2001/9/31");
System.out.println(date.getDay());
}
}
Returns the day of the week represented by this date. The returned value (0 = Sunday, 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday) represents the day of the week that contains or begins with the instant in time represented by this Date object, as interpreted in the local time zone.
public static void main(String args[]){
String weekName[] = {"Mon","TUE","WEN","THR","FRI","SAT","SUN"};
int day = 18,month = 4, year = 2005, weekDay = 0;
if ((month == 1) || (month == 2)){
month += 12;
year--;
}
weekDay = (day + 2*month + 3*(month+1)/5 + year + year/4 - year/100 + year/400) % 7;
System.out.println(weekName[weekDay]);
}
}这是程序员上一篇文章介绍过的算法了,改成了Java的,呵呵,一月和二月当作前一年的13,14月处理.
您能否讲解一下这个算法,我没看明白:(
weekDay = (day + 2*month + 3*(month+1)/5 + year + year/4 - year/100 + year/400) % 7;
这个公式,文章比较长,我看的也不是很明白,我找了下,网上有这文的摘录,你可一看哈子,呵呵.
http://blog.csdn.net/ycrao/archive/2000/11/24/3825.aspx