ITeye博客

javascript获取指定时间函数

Brooke · 2011-03-16 14:03 · 学习过程 · Web前端 · Markdown

function WeekDate() {

/**  
 * 基准时间,所有计算以此为基础  
 */  
var _calcDate = new Date();   

/**  
 * 一天的豪秒数  
 */  
var _day = 1000 * 60 * 60 * 24;   

this.getThisWeekDate = getThisWeekDate;   
this.getPrevWeekDate = getPrevWeekDate;   
this.getNextWeekDate = getNextWeekDate;   
this.wrapDate = wrapDate;   

this.getDayMillisecond = getDayMillisecond;   

/**  
 * 取上周开始至上周结束日期  
 *  
 * @return Array 上周第一天 上周最后一天  
 */  
function getPrevWeekDate() {   
    // 取上周结束日期   
    var lastDay = new Date(_calcDate - (_calcDate.getDay()) * _day);   
    // 取上周开始日期   
    var firstDay = new Date((lastDay * 1) - 6 * _day);   
    // 更新基准时间   
    _calcDate = firstDay;   

    return ;   
}   

/**  
 * 取下周开始至下周结束日期  
 *  
 * @return Array 上周第一天 上周最后一天  
 */  
function getNextWeekDate() {   
    // 取下周开始日期   
    var firstDay = new Date((_calcDate * 1) + (6 - _calcDate.getDay() + 2) * _day);   
    // 取下周结束日期   
    var lastDay = new Date((firstDay * 1) + 6 * _day);   
    // 更新基准时间           
    _calcDate = firstDay;   

    return ;   
}   

function getNextWeekFirstDay(){
	var next_week=getNextWeekDate()+"";
	var next_week_day=next_week.split("-");
	//alert(next_week_day);
	return Number(next_week_day);
}
/**  
 * 取本周开始至本周结束日期  
 *  
 * @return Array 本周第一天 本周最后一天  
 */  
function getThisWeekDate() {   
    _calcDate = new Date();   
    // 第一天日期   
    var firstDay = new Date(_calcDate - (_calcDate.getDay() - 1) * _day);   
    // 最后一天日期   
    var lastDay = new Date((firstDay * 1) + 6 * _day);   

    return ;   
}   

function wrapDate($date) {   
    var m = $date.getMonth() + 1;   
    m = m < 10 ? "0" + m : m;   

    var d = $date.getDate();   
    d = d < 10 ? "0" + d : d;   

    return $date.getFullYear() + "-" + m + "-" + d;               
}   

function getDayMillisecond() {   
    return _day;   
}   

}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。