本方法主要是获取从当天算起,上个月的某一天至今天刚好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);
}