//设置怀孕多久 template.helper('setusedTime',function(o){ var now = new Date() var nowTime = now.getFullYear()+'-'+(now.getMonth()+1)+'-'+now.getDate()+' 00:00:00' var oldTime = o.split(' ')[0]+' 00:00:00' var diff = (new Date(nowTime.replace(/\-/g,'/')).getTime() - new Date(oldTime.replace(/\-/g,'/')).getTime())/24/3600/1000 var week = parseInt(diff/7) var day = diff%7 if(week == 0 && day == 0){ return day+'天' }else{ if(week == 0){ return day+'天' }else if(day == 0){ return week+'周' }else{ return week+'周'+day+'天' } } }) //设置预产期 template.helper('setExpectedTime',function(o){ var now = new Date() var nowTime = now.getFullYear()+'-'+(now.getMonth()+1)+'-'+now.getDate()+' 00:00:00' var oldTime = o.split(' ')[0]+' 00:00:00' var diff = (new Date(oldTime.replace(/\-/g,'/')).getTime() - new Date(nowTime.replace(/\-/g,'/')).getTime())/24/3600/1000 if(diff>0){ var week = parseInt(diff/7) var day = diff%7 if(week == 0){ return '距离预产期还有'+day+' 天' }else if(day == 0){ return '距离预产期还有 '+week+' 周' }else{ return '距离预产期还有 '+week+''+day+' 天' } }else{ if(diff == 0){ return '已达到预产期' }else{ var diff2 = Math.abs(diff) var week = parseInt(diff2/7) var day = diff2%7 if(week == 0){ return '已超出预产期'+day+' 天' }else if(day == 0){ return '已超出预产期 '+week+' 周' }else{ return '已超出预产期 '+week+''+day+' 天' } } } }) //取前一部分时间 template.helper('setTime',function(o){ return o.split(' ')[0] })