javascript 实现 传入周数,获取当前周的日期,周一到周天的年月日

javascript 实现 传入周数,获取当前周的日期,周一到周天的年月日,第1张

<!DOCTYPE HTML>

<html>

<head>

    <meta charset=UTF-8>

    <title>YuGiOh</title>

    <script type="text/javascript">

        var yugi = function(year, index) {

            var d = new Date(year, 0, 1);

            while (dgetDay() != 1) {

                dsetDate(dgetDate() + 1);

            }

            var to = new Date(year + 1, 0, 1);

            var i = 1;

            var arr = [];

            for (var from = d; from < to;) {

                if (i == index) {

                    arrpush(fromgetFullYear() + "年" + (fromgetMonth() + 1) + "月" + fromgetDate() + "日");

                }

                var j = 6;

                while (j > 0) {

                    fromsetDate(fromgetDate() + 1);

                    if (i == index) {

                        arrpush(fromgetFullYear() + "年" + (fromgetMonth() + 1) + "月" + fromgetDate() + "日");

                    }

                    j--;

                }

                if (i == index) {

                    return arr;

                }

                fromsetDate(fromgetDate() + 1);

                i++;

            }

        }

        var arr = yugi(2015, 52);

        consolelog(arr);

    </script>

</head>

<body></body>

</html>

function GetWeekDate(time){

var now = new Date(time); //当前日期

thisnowDayOfWeek = nowgetDay(); //今天本周的第几天

thisnowYear = nowgetYear(); //当前年

thisnowMonth = nowgetMonth(); //月

thisnowDay = nowgetDate(); //日

thisbeginHour="09:00:00";

thisendHour="23:59:59";

thisnowYear += (thisnowYear < 2000) 1900 : 0; //

thisnowDayOfWeek = thisnowDayOfWeek==07:thisnowDayOfWeek; // 如果是周日,就变成周七

}

GetWeekDateprototypedate2str=function(x,y){//date2str(new Date(curTime),"yyyy-MM-dd")

var z ={y:xgetFullYear(),M:xgetMonth()+1,d:xgetDate(),h:xgetHours(),m:xgetMinutes(),s:xgetSeconds()};

return yreplace(/(y+|M+|d+|h+|m+|s+)/g,function(v) {return ((vlength>1"0":"")+eval('z'+vslice(-1)))slice(-(vlength>2vlength:2))});

}

GetWeekDateprototypeformatDate=function(date){//格局化日期:yyyy-MM-dd

var myyear = dategetFullYear();

var mymonth = dategetMonth()+1;

var myweekday = dategetDate();

//alert("formatDate"+myyear+":"+mymonth+":"+myweekday)

if(mymonth < 10){

mymonth = "0" + mymonth;

}

if(myweekday < 10){

myweekday = "0" + myweekday;

}

return (myyear+"-"+mymonth + "-" + myweekday);

}

GetWeekDateprototypegetWeekStartDate=function(){ //获得本周的开端日期

var weekStartDate = new Date(thisnowYear, thisnowMonth, thisnowDay - thisnowDayOfWeek+1);

return thisformatDate(weekStartDate);

}

GetWeekDateprototypegetWeekEndDate=function(){//获得本周的停止日期

var weekEndDate = new Date(thisnowYear, thisnowMonth, thisnowDay + (6 - thisnowDayOfWeek+1));

return thisformatDate(weekEndDate);

}

GetWeekDateprototypegetAWeedkYMD=function(){//获得本周周一~周日的年月日

var ymdArr=[];

for (var i = 0; i < 7; i++) {

ymdArr[i]=[];

//ymdArr[i][0]=thisformatDate(new Date(thisnowYear, thisnowMonth, thisnowDay - thisnowDayOfWeek+i+1));

ymdArr[i][0]=thisdate2str(new Date(thisnowYear, thisnowMonth, thisnowDay - thisnowDayOfWeek+i+1),'yyyy-MM-dd');

ymdArr[i][1]=thisdate2str(new Date(thisnowYear, thisnowMonth, thisnowDay - thisnowDayOfWeek+i+1), 'MM月dd日');

};

return ymdArr;

}

GetWeekDateprototypegetQishu=function(time){//获得本周是指定日期(712日)的第几周

var oNDate=new Date(time); //系统当前时间

var oEDate=new Date('2015/7/12 23:59:59');

var diff= oNDategetTime()-oEDategetTime();

//consolelog(diff)

//consolelog("相差天:"+diff/(2460601000))

//consolelog("相差期数:"+parseInt(diff/(2460601000))/7)

//consolelog("取整期数:"+Mathfloor(parseInt(diff/(2460601000))/7))

return (diff/(2460601000))/7;

}

GetWeekDateprototypegetWeeksDates=function(time){//获取历史周排行的周一到周日时间段

var qishu = (thisqishu || thisqishu==0)thisqishu:thisgetQishu(time);

//var qishu=thisgetQishu(time);

var WeeksTimes=[];//存放时间的二维数组

minYear=2015,

minMonth=7,

minDay=12;

for (var i = 0; i<qishu; i++) {

var sday;

var eday;

WeeksTimes[i]=[];

if(i==0){//如果离2015-07-12只相差1期

sday=minDay+1; //开始时间+1天

}else{//如果离2015-07-12相差期数>1

sday=minDay+1+7i;

}

eday=minDay+7(i+1);//结束时间+7天

WeeksTimes[i][0]=thisformatDate(new Date(minYear,minMonth-1,sday))+" "+thisbeginHour;

WeeksTimes[i][1]=thisformatDate(new Date(minYear,minMonth-1,eday))+" "+thisendHour;

};

//如果是一周的周日就不要减去一期

return WeeksTimes;

}

GetWeekDateprototypetodayData=function(json){//处理tender_list_weekjsp页面

var oQishu=$('qishu');

iQishu=thisqishu;//期数+1是因为,相差0期就是第1期

oThisWeekListBtn=$('total_list_btn'),//查看本周排行榜按钮

sTime=thisgetWeekStartDate()+" "+thisbeginHour,

eTime=thisgetWeekEndDate()+" "+thisendHour;

//1、修改期数

//consolelog("相差周:"+iQishu);

if(/^[1-9]\d$/test(iQishu) || iQishu==0){//整数 +3

oQishuhtml(iQishu1+3);

}else{

oQishuhtml(Mathfloor(iQishu)1+4);

}

oThisWeekListBtnattr("onclick","showWeekList('"+sTime+"','"+eTime+"')");//2、修改查看本周排行榜的起止时间

}

GetWeekDateprototypehistoryData=function(time){//处理tender_list_weekjsp页面

var oQishu=$('qishu'),

oDateList=$('#dateList'), //顶部导航时间

oHistoryList=$('#history_cont'),//历史周

aThisWeekYMD=thisgetAWeedkYMD(),//本周周一~周日的年月日

aThisWeekDates=thisgetWeeksDates(time);//获取历史周排行的周一到周日时间段

iQishu=thisqishu;

//consolelog("相差周:"+iQishu);

//1、修改期数,+4是加上前3期,在+1是如果间隔3期,当前就是第4期

//如果时间23:59:59是正整数(-1),如果是0整数(3),如果是非整数(向下取整),或负数(向上取整)但是负数不考虑

//oQishuhtml(iQishu1+3);

if(/^[1-9]\d$/test(iQishu) || iQishu==0){//整数 +3

oQishuhtml(iQishu1+3);

}else{

oQishuhtml(Mathfloor(iQishu)1+4);

}

//2、给顶部时间追加时间

for (var i = 0; i < aThisWeekYMDlength; i++) {

var str='<li data-time="'+aThisWeekYMD[i][0]+'">'+aThisWeekYMD[i][1]+'</li>';

$(str)appendTo(oDateList);

};

//3、给历史周排行榜添加周期数

if(thisqishu>1){//如果相差的期数大于1期

//consoledir(aThisWeekDates)

for (var j = 0; j < aThisWeekDateslength-1; j++) {

var iQiNum=j+4;

var str='<li onclick="showWeekList(\''+aThisWeekDates[j][0]+'\',\''+aThisWeekDates[j][1]+'\')">第'+iQiNum+'期</li>';

$(str)prependTo(oHistoryList);

};

}

}

GetWeekDateprototypeinit=function(time){

var iQishu=thisgetQishu(time),//期数+1是因为,相差0期就是第1期

json={};

jsonqishu=iQishu;

thisqishu=iQishu;

if($('#pageType')val()=="today"){//如果是tender_list_weekjsp页面

if(new Date(time)getTime() < new Date('2015/07/12 23:59:59')getTime()){//特殊处理时间小于20150712

$('qishu')html('3');

$('total_list_btn')attr("onclick","showWeekList('2015-07-03 09:00:00','2015-07-12 23:59:59')");

return false;

}

thistodayData(json);

}else if($('#pageType')val()=="history"){

if(new Date(time)getTime() < new Date('2015/07/12 23:59:59')getTime()){//特殊处理时间小于20150712

$('qishu')html('3');

$('#dateList')addClass('dateList2')html('<li data-time="2015-07-03">07月03日</li><li data-time="2015-07-04">07月04日</li><li data-time="2015-07-05">07月05日</li><li data-time="2015-07-06">07月06日</li><li data-time="2015-07-07">07月07日</li><li data-time="2015-07-08">07月08日</li><li data-time="2015-07-09">07月09日</li><li data-time="2015-07-10">07月10日</li><li data-time="2015-07-11">07月11日</li><li data-time="2015-07-12">07月12日</li>');

$('#history_cont')html('<li onclick="showWeekList(\'2015-06-26 09:00:00\',\'2015-07-02 23:59:59\')">第二期</li><li onclick="showWeekList(\'2015-06-19 12:00:00\',\'2015-06-25 23:59:59\')">第一期</li>');

return false;

}

thishistoryData(time);

}

//consoledir(thisgetWeeksDates(time));

};

DateTime dt = new DateTime(2009, 6,5);

前一天 dtAddDays(-1);

期一周 dtAddDays(-7);

前一月 dtAddMonths(-1);

前一年 dtAddYears(-1);

public static List<Date> dateToWeek(Date mdate){

int b=mdategetDay();

Date fdate ;

List <Date> list = new ArrayList();

Long fTime=mdategetTime()-b243600000;

for(int a=0;a<8;a++){

fdate= new Date();

fdatesetTime(fTime+(a243600000));

listadd(a, fdate);

}

return list;

}

调用这个方法 你传入一个日期 就能获得 这个日期所在一周内的所有天数的一个List

当前时间 select getdate()

当前时间周的起始日期(以周一为例)select DATEADD(week,DATEDIFF(week,0,getdate()),0)

上周起始:select dateadd(week,-1,DATEADD(week,DATEDIFF(week,0,getdate()),0))

上上周起始:select dateadd(week,-2,DATEADD(week,DATEDIFF(week,0,getdate()),0))

上上上周起始:select dateadd(week,-3,DATEADD(week,DATEDIFF(week,0,getdate()),0))

周七以此类推

以上就是关于javascript 实现 传入周数,获取当前周的日期,周一到周天的年月日全部的内容,包括:javascript 实现 传入周数,获取当前周的日期,周一到周天的年月日、如何获取本周的起止日期、.net 如何得出给定日期的前一天,前一周,前一月,前一年等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/10059482.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-04
下一篇 2023-05-04

发表评论

登录后才能评论

评论列表(0条)

保存