飞翔天空

自娱自乐

« ASP.Net (C#) 中出现的一些问题 IP地址信息查询(WHOIS)服务的原理 »

设置两个文档框的查询时间段

设置两个个文本框的: [今天] [昨天] [本周] [上周] [最近一周] [本月] [最近一月] [上月] 等时间段


~


[今天] [昨天] [本周] [上周] [最近一周] [本月] [最近一月] [上月]




下面是javascript代码;

// JavaScript Document

//设置时间
function Setupdatetime(s,sv,e,ev)
{
var temp_sdate = new Date();
temp_sdate.setDate(temp_sdate.getDate()+sv);

document.getElementById(s).value=temp_sdate.getYear() + "-" + (temp_sdate.getMonth()+1) + "-" + temp_sdate.getDate();
var temp_edate=new Date();
temp_edate.setDate(temp_edate.getDate()+ev);
document.getElementById(e).value=temp_edate.getYear() + "-" + (temp_edate.getMonth()+1) + "-" + temp_edate.getDate();
}

//按周设置
function SetupWeek(s,sv,e)
{
var temp_sdate = new Date();
temp_sdate.setDate(temp_sdate.getDate()-(sv*7));
document.getElementById(e).value=temp_sdate.getYear() + "-" + (temp_sdate.getMonth()+1) + "-" + temp_sdate.getDate();

var day = temp_sdate.getDay();
temp_sdate.setDate(temp_sdate.getDate()-day);
document.getElementById(s).value=temp_sdate.getYear() + "-" + (temp_sdate.getMonth()+1) + "-" + temp_sdate.getDate();
}


//按月设置
function SetupMonth(s,sv,e)
{
var temp_sdate = new Date();
temp_sdate.setMonth(temp_sdate.getMonth()-sv)
document.getElementById(s).value=temp_sdate.getYear() + "-" + (temp_sdate.getMonth()+1) + "-" + "1";
if(sv==0){
document.getElementById(e).value=temp_sdate.getYear() + "-" + (temp_sdate.getMonth()+1) + "-" + temp_sdate.getDate();
}else
{
document.getElementById(e).value=temp_sdate.getYear() + "-" + (temp_sdate.getMonth()+1) + "-" + DateSelectorDaysInMonth(temp_sdate.getYear(),(temp_sdate.getMonth()+1));
}
}


//根据年和月获取当月的天数
function DateSelectorDaysInMonth(year, month)
{
var date = new Date(year,month,0);
return date.getDate();
}
  • 相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新评论及回复

最近发表

Powered By Z-Blog 1.8 Devo Build 80201

Copyright www.52z.com