/***
* 获得当前时间
*/
function getCurrentDate(){
return new Date();
};
//今年以来的起止时间段
function getThisYear(){
//起止日期数组
var startStop=new Array();
//获取当前时间
var currentDate=this.getCurrentDate();
var stop = currentDate.getYear()+"-"+(currentDate.getMonth()+1)+"-"+currentDate.getDate();
var start = currentDate.getYear()+"-"+"01-01";
//添加年初时间
startStop.push(start);//本周起始时间
//添加当前时间
startStop.push(stop);//本周终止时间
//返回
return startStop;
}
//获得昨日起止时间
function getYesterdayDate(){
//起止日期数组
var startStop=new Array();
//获取当前时间
var currentDate=this.getCurrentDate();
//一天的毫秒数
var millisecond=1000*60*60*24;
//昨日时间
yesterday = new Date(currentDate.getTime()-millisecond);
currentDate = currentDate.getYear()+"-"+(currentDate.getMonth()+1)+"-"+currentDate.getDate();
yesterday = yesterday.getYear()+"-"+(yesterday.getMonth()+1)+"-"+yesterday.getDate();
//添加本周时间
startStop.push(yesterday);//本周起始时间
//添加本周最后一天时间
startStop.push(currentDate);//本周终止时间
//返回
return startStop;
}
/***
* 获得本周起止时间
*/
function getCurrentWeek(){
//起止日期数组
var startStop=new Array();
//获取当前时间
var currentDate=this.getCurrentDate();
//返回date是一周中的某一天
var week=currentDate.getDay();
//返回date是一个月中的某一天
var month=currentDate.getDate();
//一天的毫秒数
var millisecond=1000*60*60*24;
//减去的天数
var minusDay=week!=0?week-1:6;
//alert(minusDay);
//本周 周一
var monday=new Date(currentDate.getTime()-(minusDay*millisecond));
//本周 周日
var sunday=new Date(monday.getTime()+(6*millisecond));
monday = monday.getYear()+"-"+(monday.getMonth()+1)+"-"+monday.getDate();
sunday = sunday.getYear()+"-"+(sunday.getMonth()+1)+"-"+sunday.getDate();
//添加本周时间
startStop.push(monday);//本周起始时间
//添加本周最后一天时间
startStop.push(sunday);//本周终止时间
//返回
return startStop;
};
/***
* 获得本月的起止时间
*/
function getCurrentMonth(){
//起止日期数组
var startStop=new Array();
//获取当前时间
var currentDate=getCurrentDate();
//获得当前月份0-11
var currentMonth=currentDate.getMonth();
//获得当前年份4位年
var currentYear=currentDate.getFullYear();
//求出本月第一天
var firstDay=new Date(currentYear,currentMonth,1);
//当为12月的时候年份需要加1
//月份需要更新为0 也就是下一年的第一个月
if(currentMonth==11){
currentYear++;
currentMonth=0;//就为
}else{
//否则只是月份增加,以便求的下一月的第一天
currentMonth++;
}
//一天的毫秒数
var millisecond=1000*60*60*24;
//下月的第一天
var nextMonthDayOne=new Date(currentYear,currentMonth,1);
//求出上月的最后一天
var lastDay=new Date(nextMonthDayOne.getTime()-millisecond);
firstDay = firstDay.getYear()+"-"+(firstDay.getMonth()+1)+"-"+firstDay.getDate();
lastDay = lastDay.getYear()+"-"+(lastDay.getMonth()+1)+"-"+lastDay.getDat
js上周(月、季)、上上周(月、季)、去年同期上周(月、季)
最新推荐文章于 2024-11-19 12:24:25 发布