日期:2014-05-16 浏览次数:20398 次
//js日期解析函数 function alertparseDate(s){ var today = new Date(); /(\d+)\/(\d+)\/(\d+)\s*(\d*):?(\d*)/.exec(s); var ymd = s.split(' '); var ymd_r = ymd[0].split('/'); var his_r = ymd[1].split(':'); var m1 = (ymd_r[0] && ymd_r[0] > 1899 && ymd_r[0] < 2101) ? parseFloat(ymd_r[0]) : today.getFullYear(); var m2 = (ymd_r[1] && (ymd_r[1] > 0 && ymd_r[1] < 13)) ? parseFloat(ymd_r[1]) : today.getMonth() + 1; var m3 = (ymd_r[2] && (ymd_r[2] > 0 && ymd_r[2] < 32)) ? parseFloat(ymd_r[2]) : today.getDate(); var m4 = (his_r[0] && (his_r[0] > -1 && his_r[0] < 24)) ? parseFloat(his_r[0]) : 0; var m5 = (his_r[1] && (his_r[1] > -1 && his_r[1] < 60)) ? parseFloat(his_r[1]) : 0; /(\d+)\/(\d+)\/(\d+)\s*(\d*):?(\d*)/.exec("0000-00-00 00\:00"); var date2 = new Date(m1, m2 - 1, m3, m4, m5); //用距标准时间差来获取相距时间 var minsec = Date.parse(today) - Date.parse(date2); var days = minsec / 1000 / 60 / 60 / 24; //factor: second / minute / hour / day return parseInt(days); }
/(\d+)\/(\d+)\/(\d+)\s*(\d*):?(\d*)/.exec(s);