JK_10000(JK) 是对的,但是出来的数据是Sat Aug 6 12:57:46 UTC+0800 2005 怎么样才能将它转化为2005/08/06阿
<SCRIPT LANGUAGE="JavaScript"> <!-- function Date.prototype.toString(){ return this.getFullYear()+"年"+(this.getMonth()+1)+"月"+this.getDate()+"日"; } var d = new Date();var d1 = new Date(d-(d.getDay()-1)*86400000);var d0 = new Date((d1/1000+6*86400)*1000); alert("本局从"+d1+"到"+d0); //--> </SCRIPT>
你要得到的是“2005/08/06”这样啊 稍微改动下 <SCRIPT LANGUAGE="JavaScript"> <!-- function Date.prototype.toString(){ return this.getFullYear()+"/"+("0"+(this.getMonth()+1)).substr((("0"+(this.getMonth()+1)).length-2),2)+"/"+("0"+this.getDate()).substr((("0"+this.getDate()).length-2),2); } var d = new Date();var d1 = new Date(d-(d.getDay()-1)*86400000);var d0 = new Date((d1/1000+6*86400)*1000); alert("本局从"+d1+"到"+d0); //--> </SCRIPT>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html>
<head>
<title>Untitled</title>
<Script language="javascript">
<!--
function fncS_date()
{
var Dates= new Date()
var Weeks=Dates.getDay();
var Days=Dates.getDate();
var Mons=Dates.getMonth()+1;
var Years=Dates.getYear();
var temp_start
temp_start=Days-Weeks+1;
if (temp_start<=0)
{
Mons--;
if (Mons<=0)
{
Years--;
Mons=12+Mons;
if (Mons>9)
{
if (Mons % 2 ==0)
{
if (Mons==2)
{
if (Years%4==0)
{
temp_start=29+temp_start;
}
else
{
temp_start=28+temp_start;
}
}
else
{
temp_start=30+temp_start;
}
}
else
{
temp_start=31+temp_start;
}
}
else
{
if (Mons % 2 !=0)
{
temp_start=30+temp_start;
}
else
{
temp_start=31+temp_start;
}
}
}
}
alert(Years+"/"+Mons+"/"+temp_start);
}
function fncE_date()
{
var Dates= new Date()
var Weeks=Dates.getDay();
var Days=Dates.getDate();
var Mons=Dates.getMonth()+1;
var Years=Dates.getYear();
var temp_end;
temp_end=Days+7-Weeks;
if (Mons!=12)
{
if (Years%4==0)
{
if (Mons==2)
{
if (temp_end>29)
{
Mons++;
temp_end=temp_end-29;
}
}
else
{
if (Mons<9)
{
if (Mons%2==0)
{
if (temp_end>30)
{
Mons++;
temp_end=temp_end-30;
}
}
else
{
if (temp_end>1)
{
Mons++;
temp_end=temp_end-31;
}
}
}
else
{
if (Mons%2==0)
{
if (temp_end>31)
{
Mons++;
temp_end=temp_end-31;
}
}
else
{
if (temp_end>30)
{
Mons++;
temp_end=temp_end-30;
}
}
}
}
}
else
{
if (Mons==2)
{
if (temp_end>28)
{
Mons++;
temp_end=temp_end-28;
}
}
else
{
if (Mons>9)
{
if (Mons%2==0)
{
if (temp_end>30)
{
Mons++;
temp_end=temp_end-30;
}
}
else
{
if (temp_end>31)
{
Mons++;
temp_end=temp_end-31;
}
}
}
else
{
if (Mons%2==0)
{
if (temp_end>31)
{
Mons++;
temp_end=temp_end-31;
}
}
else
{
if (temp_end>30)
{
Mons++;
temp_end=temp_end-30;
}
}
}
}
}
}
else
{
if(temp_end>31)
{
Years++;
Mons=1;
if (temp_end>31)
{
temp_end=temp_end-31;
}
}
}
alert(Years+"/"+Mons+"/"+temp_end);
}
//-->
</Script>
</head><body>
<input type="button" name="btnS_date" value="本周周一日期" onclick="fncS_date()">
<input type="button" name="btnS_date" value="本周周日日期" onclick="fncE_date()"></body>
</html>
var time_1 = new Date();
y_1 = time_1.getYear();
m_1 = time_1.getMonth()+1;
d_1 = time_1.getDate();
wd_1 = time_1.getDay();
switch(wd_1)
{
case 1:
s_1 = d_1;
e_1 = d_1+6;
break;
case 2:
s_1 = d_1 -1;
e_1 = d_1 + 5;
break;
case 3:
s_1 = d_1 -2;
e_1 = d_1 + 4;
break;
case 4:
s_1 = d_1 -3;
e_1 = d_1 + 4;
break;
case 5:
s_1 = d_1 -4;
e_1 = d_1 + 3;
break;
case 6:
s_1 = d_1 -5;
e_1 = d_1 + 2;
break;
case 7:
s_1 = d_1 -6;
e_1 = d_1 + 1;
break;
}
document.write("s:" +y_1+"年"+m_1+"月"+s_1+"日"+"e:" + y_1+"年"+m_1+"月"+e_1+"日");
</script>
var d1 = new Date();
d1.setDate(d1.getDate()-d1.getDay()+1);
alert("当前周的周一是:"+d1);
d1.setDate(d1.getDate()+6);
alert("当前周的周日是:"+d1);</script>
其实在创建日期对象时,我们可以指定时间,而若这个日期是一个非法的,就比如这个,它就会自己去计算,哈哈~~~这样其实就等于是new Date(2001,4,1)了,然后,我们就可以使用该日期对象来获取日期对象实例的getDate(),getMonth()等等,像楼主这样要搞到之前几天几月的日期,不应该用上面那些人的办法,那些太笨了,用JK的办法吧
怎么样才能将它转化为2005/08/06阿
<!--
function Date.prototype.toString(){
return this.getFullYear()+"年"+(this.getMonth()+1)+"月"+this.getDate()+"日";
}
var d = new Date();var d1 = new Date(d-(d.getDay()-1)*86400000);var d0 = new Date((d1/1000+6*86400)*1000);
alert("本局从"+d1+"到"+d0);
//-->
</SCRIPT>
稍微改动下
<SCRIPT LANGUAGE="JavaScript">
<!--
function Date.prototype.toString(){
return this.getFullYear()+"/"+("0"+(this.getMonth()+1)).substr((("0"+(this.getMonth()+1)).length-2),2)+"/"+("0"+this.getDate()).substr((("0"+this.getDate()).length-2),2);
}
var d = new Date();var d1 = new Date(d-(d.getDay()-1)*86400000);var d0 = new Date((d1/1000+6*86400)*1000);
alert("本局从"+d1+"到"+d0);
//-->
</SCRIPT>