js获取至今天一个月的时间

来源:互联网 发布:ps软件源码下载 编辑:程序博客网 时间:2024/06/06 00:27
本方法主要是获取从当天算起,上个月的某一天至今天刚好30天的时间。 
 特别声明IE8和IE9中parseInt对字符解析的不一想IE8只针对前两位,而IE9则解析全部。
 
 
 
function dataInfo(){  var date = new Date();  var year = date.getYear()+1900;  if ($.browser.msie) {   var version = navigator.userAgent.toString().split("MSIE");   var value = version[1].substring(0,version[1].indexOf(";"));   if(value>8){    year = date.getYear()+1900;   }else{    year = date.getYear();   }  }  var month = date.getMonth()+1;  month = month>9?month:('0'+month);  var lastMDay = new Date(year,month-1,0).getDate();  var lastDay = new Date().getDate();  var firstDay = parseInt(lastDay)-29;  if(firstDay>0){   alert(year+'-'+month+'-0'+firstDay);  }else{   firstDay = firstDay+parseInt(lastMDay);   alert(year+'-0'+(month-1)+'-'+firstDay>9?firstDay:'0'+firstDay);  }   alert(year+'-'+month+'-'+lastDay>9?lastDay:'0'+lastDay); }

 

0 0
原创粉丝点击