123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- //设置怀孕多久
- 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 '距离预产期还有<span>'+day+'</span> 天'
- }else if(day == 0){
- return '距离预产期还有 <span>'+week+'</span> 周'
- }else{
- return '距离预产期还有 <span>'+week+'</span> 周 <span>'+day+'</span> 天'
- }
- }else{
- if(diff == 0){
- return '已达到预产期'
- }else{
- var diff2 = Math.abs(diff)
- var week = parseInt(diff2/7)
- var day = diff2%7
- if(week == 0){
- return '已超出预产期<span class="red">'+day+'</span> 天'
- }else if(day == 0){
- return '已超出预产期 <span class="red">'+week+'</span> 周'
- }else{
- return '已超出预产期 <span class="red">'+week+'</span> 周 <span class="red">'+day+'</span> 天'
- }
- }
- }
- })
- //取前一部分时间
- template.helper('setTime',function(o){
- return o.split(' ')[0]
- })
|