javascript 根据年月日计算星期 - IDC资讯网_站长学院 - Java PHP Flex Python Ajax CSS 编程 开源 学习 总结 分享

function getWeek(y, m, d) {
  var weekNumbers=new Array(7);
  weekNumbers[0]="sunday";
  weekNumbers[1]="monday";
  weekNumbers[2]="tuesday";
  weekNumbers[3]="wednesday";
  weekNumbers[4]="thursday";
  weekNumbers[5]="friday";
  weekNumbers[6]="saturday";
 
  var _int = parseInt,
  c = _int(y/100);
  y = y.toString().substring(2, 4);
  y = _int(y, 10);
  if(m === 1) {
    m = 13;
    y--;
  } else if(m === 2) {
    m = 14;
    y--;
  };
       
  var w = y + _int(y/4) + _int(c/4) - 2*c + _int(26*(m+1)/10) + d - 1;
  w = w%7;
 
  var weekno = w >= 0 ? w : w+7;
  return weekNumbers[weekno];
}
 
编程语言 | 评论(0) | 引用(0) | 阅读(15499)