2个回答
展开全部
<script>
function tab(date){
var oDate = new Date();
var nY = oDate.getFullYear();
var nM = oDate.getMonth();
var nD = oDate.getDate();
var newDate = new Date(nY,nM,nD,0,0,0);
var date = date.split('-');
var lastDate = new Date(date[0],(date[1]-1),date[2],0,0,0);
var result = '';
if(newDate.getTime() > lastDate.getTime()){
result = date[0]+'年'+date[1]+'月'+date[2]+'日到今天已经过去了('+ (newDate.getTime()-lastDate.getTime())/86400000 +')天了';
}else{
result = date[0]+'年'+date[1]+'月'+date[2]+'日到今天还有('+ Math.abs(newDate.getTime()-lastDate.getTime())/86400000 +')天了';
}
return result;
}
console.log(tab('2015-09-20'));
</script>
展开全部
function comptime(beginTime, endTime){
//var beginTime = "2009-09-21 00:00:00";
//var endTime = "2009-09-25 00:00:00";
var beginTimes=beginTime.substring(0,10).split('-');
var endTimes=endTime.substring(0,10).split('-');
beginTime=beginTimes[1]+'-'+beginTimes[2]+'-'+beginTimes[0]+' '+beginTime.substring(10,19);
endTime=endTimes[1]+'-'+endTimes[2]+'-'+endTimes[0]+' '+endTime.substring(10,19);
//alert(Date.parse(endTime));
//alert(Date.parse(beginTime));
var a =(Date.parse(endTime)-Date.parse(beginTime))/3600/1000;
}
//var beginTime = "2009-09-21 00:00:00";
//var endTime = "2009-09-25 00:00:00";
var beginTimes=beginTime.substring(0,10).split('-');
var endTimes=endTime.substring(0,10).split('-');
beginTime=beginTimes[1]+'-'+beginTimes[2]+'-'+beginTimes[0]+' '+beginTime.substring(10,19);
endTime=endTimes[1]+'-'+endTimes[2]+'-'+endTimes[0]+' '+endTime.substring(10,19);
//alert(Date.parse(endTime));
//alert(Date.parse(beginTime));
var a =(Date.parse(endTime)-Date.parse(beginTime))/3600/1000;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询