根据当前时间计算上月月初到月末


function getDate() {   var d = new Date();   var year = d.getYear();   var month = d.getMonth();//不+1代表上个月   var month2 = d.getMonth()+1;//+1代表本月   var date = d.getDate();   var day = d.getDay();   if (month > 9)     month= month;   else     month= "-0" +month;   if (month2 > 9)     month2= month2;   else     month2= "-0" +month2;   if (date > 9)
    date=date;   else     date="-0"+date;   var lastday=getLastDay(year,month2);   if (lastday > 9)     lastday=lastday;   else     lastday="-0"+lastday;   var ls_date1 = year + month+"-01";//取上全月头一天2009-08-01   var ls_date2 = year + month+"-" + getLastDay(year,month2);//取上个月最后一天   alert("ls_date1=" + ls_date1);   alert("ls_date2=" + ls_date2); } function getLastDay(year, month) {   var new_year = year; //取当前的年份   var new_month = month++;//取下一个月的第一天,方便计算(最后一天不固定)   if (month > 12) { //如果当前大于12月,则年份转到下一年     new_month -= 12; //月份减     new_year++; //年份增   }   var newnew_date = new Date(new_year, new_month, 1); //取当年当月中的第一天   return (new Date(newnew_date.getTime() - 1000 * 60 * 60 * 24)).getDate();//获取当月最后一天日期 }

转载于:https://www.cnblogs.com/gy-1029/p/3727397.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值