js根据当前时间获取当前季度,月份,和第几周

function jidu()
  {
   var getMonthWeek = function (a, b, c) {
    var date = new Date(a, parseInt(b) - 1, c), w = date.getDay(), d = date.getDate();
    return Math.ceil( (d + 6 - w) / 7 );
   };
  
   var getYearWeek = function (a, b, c) {
    var date1 = new Date(a, parseInt(b) - 1, c), date2 = new Date(a, 0, 1),
    d = Math.round((date1.valueOf() - date2.valueOf()) / 86400000);
    return Math.ceil( (d + ((date2.getDay() + 1) - 1)) / 7 );
   };

   var today = new Date();//获取当前时间
   var y = today.getFullYear();
   var m = today.getMonth()+1;
   var d = today.getDate();
   //document.write("今天是:",y,"-", m, "-", d, "<br/>");
   //document.write( "今天是",y,"年的第 ", getYearWeek(y, m, d), " 周<br/>" );
   //document.write( "今天是",m,"月的第 ", getMonthWeek(y, m, d), " 周<br/>" );
   var quarter = "";
   var result = getYearWeek(y, m, d);
   if (m <4) {
    quarter = 1;
    week = result;
   } else if (m < 7) {
    quarter = 2;
    week = result - getYearWeek(y, 4, 1);
    var day = new Date(y, 4, 1);
    if (day.getDay() > 1) {
     week += 1;
    }
   } else if (m < 10) {
    quarter = 3;
    week = result - getYearWeek(y, 7, 1);
    var day = new Date(y, 7, 1);
    if (day.getDay() > 1) {
     week += 1;
    }
   } else {
    quarter = 4;
    week = result - getYearWeek(y, 10, 1);
    var day = new Date(y, 10, 1);
    if (day.getDay() > 1) {
     week += 1;
    }
   }
   //document.write( "今天是第",quarter,"季度的第 ", week, " 周" );

document.write( quarter);
  }

 

转载于:https://www.cnblogs.com/275147378abc/p/5618052.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值