<Script lanaguage=JavaScript>
///////////////////////////////////////////////////////////////////////
 function str_change(str)
 {
var i,j,k,tempyear,tempmonth,tempday;
k=str.length;
i=str.indexOf("-",0);
j=str.indexOf("-",i+1);
if(j==7)
   {
   tempmonth=str.substr(i+1,2);
   }
   if(j==6)
   {
   tempmonth="0"+str.substr(i+1,1);
   }
 if(parseInt(k)-parseInt(j)==3)
 {
   tempday=str.substr(j+1,2);
   }
 if(parseInt(k)-parseInt(j)==2)
 {
tempday="0"+str.substr(j+1,1);
 }
tempyear=str.substring(0,4);
return(tempyear+tempmonth+tempday); 
}    ////////////////////////////////////////////////////////////////////////////////////////////////
  function solarDays(year) 
{
      return(((year%4 == 0) && (year%100 != 0) || (year%400 == 0))? 29: 28)//判断当年二月份的天数
}
  ///////////////////////////////////////////////////////////////////////////////////////////////
  
  function count_time(str)
  {
  tempyear=str.substring(0,4);
  tempmonth=str.substring(4,6);
  if(str.substring(4,5)=="0")
  {
  tempmonth=str.substring(5,6);
  }
  tempday=str.substring(6,8);
  if(str.substring(6,7)=="0")
  {
  tempday=str.substring(7,8);
  } 
   
var tempday1=parseInt(tempday);
var tempmonth1=parseInt(tempmonth);
var tempyear1=parseInt(tempyear);
var run_days=parseInt(solarDays(tempyear1));
var tempday2=tempday1;
var tempmonth2=tempmonth1;
var tempyear2=tempyear1; if(tempday1>run_days)
    {
    if(tempmonth1==2)
    {
tempday2=parseInt(tempday1-run_days);
tempmonth2=parseInt(tempmonth1+1);
tempyear2=tempyear1;
}
}
    if(tempday1>30)
{
if(tempmonth1==4||tempmonth1==6||tempmonth1==9||tempmonth1==11)
{
tempday2=parseInt(tempday1-30);
tempmonth2=parseInt(tempmonth1+1);
tempyear2=tempyear1;

}
if(tempday1>31)
{
if(tempmonth1==1||tempmonth1==3||tempmonth1==5||tempmonth1==7||tempmonth1==8||tempmonth1==10||tempmonth1==12)
{
tempday2=parseInt(tempday1-31);
if(tempmonth1<12)
{
tempmonth2=parseInt(tempmonth1+1);
tempyear2=tempyear1;
}
else 
{
tempmonth2=1;
tempyear2=parseInt(tempyear1+1);
}
}
} if(tempmonth2<10)

var mm="0"+String(tempmonth2);
}
else
{
var mm=String(tempmonth2);
}
if(tempday2<10)
{
var dd="0"+String(tempday2);
}
else
{
var dd=String(tempday2);
}
var yy=String(tempyear2);
var str1=String(yy+mm+dd);
   return(str1);
}
  ///////////////////////////////////////////////////////////////////////
 function check(slsj,gzsx)
 {   
    var slsj_1=str_change(slsj);//////////////////调用函数////////////////
  tempyear=slsj_1.substring(0,4);
  tempmonth=slsj_1.substring(4,6);
  if(slsj_1.substring(4,5)=="0")
  {
  tempmonth=slsj_1.substring(5,6);
  }
  tempday=slsj_1.substring(6,8);
  if(slsj_1.substring(6,7)=="0")
  {
  tempday=slsj_1.substring(7,8);
  } 
  var tempday1=parseInt(tempday);
  var tempmonth1=parseInt(tempmonth);
  var tempyear1=parseInt(tempyear);
  var bz1;var my_date;var i=0;var j=0;
///////////////////////////////////////--------循环开始--------////////////////////
 while(i<=gzsx-1){
tempday1=tempday1+1;
//alert(tempday1);
j++;
var yy,mm,dd;
   yy=String(tempyear1);
   if(tempmonth1<10)

mm="0"+String(tempmonth1);
}
else
{
mm=String(tempmonth1);
}
if(tempday1<10)
{
dd="0"+String(tempday1);
}
else
{
var dd=String(tempday1);
}
var yy_mm_dd=String(yy+mm+dd);
////////////////////调用函数,返回新日期字符串//////////////////////
my_date=count_time(yy_mm_dd);
///////////////////////////////////////////////////
temp1year=my_date.substring(0,4);
temp1month=my_date.substring(4,6);
temp1day=my_date.substring(6,8);   
 if(my_date.substring(4,5)=="0")
  {
  temp1month=my_date.substring(5,6);
  }
  if(my_date.substring(6,7)=="0")
  {
   temp1day=my_date.substring(7,8);
  } 
  var temp1day1=parseInt(temp1day);//////////////////////将字符串拆开成整数//////////////////
 // alert(temp1day1);
  var temp1month1=parseInt(temp1month);
  var temp1year1=parseInt(temp1year);
  tempday1=temp1day1;
  tempmonth1=temp1month1;
  tempyear1=temp1year1;
      bz1=temp1year1+"-"+temp1month1+"-"+temp1day1;
  //alert(bz1);
  var newdate_0=new Date(parseInt(temp1year1),parseInt(temp1month1)-1,parseInt(temp1day1));/////////进行判断是否为周末//
  var weekday_0=newdate_0.getDay();
 if(parseInt(weekday_0)==0||parseInt(weekday_0)==6)
{
i++;
}

  }
return(bz1+"#"+j);
 }

解决方案 »

  1.   

    其实我想可能你这个做起来 要简单的多,只要知道年份月份(判断是不是闰年),就知道这个约有多少天(参数daycount),循环daycount次,每次天数加1,然后判断是不是周末,是的话就输出,不是就跳过,不知道你的要求是不是这样。
      

  2.   

    不错,只不过是javascript的,不知道有没有java的.或者总结出一下规律,我自己写也行?
      

  3.   

    思路大体上就是这个思路,用java写也一样的。判断是否是周末有专门的函数。