javascript 日期 獲取周等

//判斷某一日屬於這一年的第幾周
function weekofday(data) {
    var dt = new Date(data);
    var y = dt.getFullYear();
    var start = "1/1/" + y;
    start = new Date(start);
    starts = start.valueOf();
    startweek = start.getDay();
    dtweek = dt.getDay();
    var days = Math.round((dt.valueOf() - start.valueOf()) / (24 * 60 * 60 * 1000)) - (7 - startweek) - dt.getDay() - 1;
    days = Math.floor(days / 7);
    return (days + 3);
}
//獲取當前周的週一和週末的日期
function showFEDateOfWeek(time) {
    oToday = new Date(time);
    currentDay = oToday.getDay();
    if (currentDay == 0) { currentDay = 7; };
    mondayTime = oToday.getTime() - (currentDay - 1) * 24 * 60 * 60 * 1000;
    sundayTime = oToday.getTime() + (7 - currentDay) * 24 * 60 * 60 * 1000;
    //alert(weekofday(time));
   // alert("今天是" + oToday.getDate() + "號,星期" + currentDay + "\r");
    //alert("週一是" + new Date(mondayTime).getDate() + "號,週日是" + new Date(sundayTime).getDate() + "號");
    return new Date(mondayTime).formatDate("yyyy-MM-dd") + ";" + new Date(sundayTime).formatDate("yyyy-MM-dd");
  }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章