拉尔森函数,用来根据日期计算星期几
现在的函数输入字符串的格式是:yyyy-MM-dd
例如:2011-01-22
输出是字符串:星期六
/**
* James larsson method.Caculate week from date.
* @param date fromat:yyyy-MM-dd
* @return
*/
private String CaculateWeekDay(String date)
{
String dateYear = date.substring(0, 4);
String dateMonth = date.substring(5, 7);
String dateDay = date.substring(8, 10);
int y = Integer.parseInt(dateYear);
int m = Integer.parseInt(dateMonth);
int d = Integer.parseInt(dateDay);
if(m==1||m==2) {
m+=12;
y--;
}
int iWeek=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;
switch(iWeek)
{
case 0:
return this.getString(“周一”);
case 1:
return this.getString(“周二”);
case 2:
return this.getString(“周三”);
case 3:
return this.getString(“周四”);
case 4:
return this.getString(“周五”);
case 5:
return this.getString(“周六”);
case 6:
return this.getString(“周日”);
}
return "";
}