用getDay得到当前日期是星期几,然后向前、向后加天数,得到当前一周的起始日和终了日
解决方案 »
- .net当中用Javascript给LI标签设置样式
- Ext中formPanel面板布局 愁死了
- 不显示删除回复显示所有回复显示星级回复显示得分回复 关于onmouseover显示onmouseout隐藏的问题,高分求助。
- 如何用JS画线?如何用JS画线让两个DIV相连
- 选中复选框后能不能让其关联的label控件变色?
- jquery切换图问题
- 高手请进
- 急需chinaren相册图片滚动和幻灯片播放的效果的代码
- 大家来解密~~~
- 如何实现网站程序访问自已以外的网站发送到客户的Cookies
- 100分求:javascript中调用application的方法
- 推荐一个带农历的日历(程序有点小错,请高手进来修正)
<!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>