function check_tdate(odate){ var checkArray= new Array() ; //nowArray = odate.split(" "); checkArray = odate.split("-"); checkDate = new Date(checkArray[0],checkArray[1],checkArray[2]); var nowTime = new Date();// 现在时间 var the_year = nowTime.getYear(); var the_month = nowTime.getMonth() + 1; var the_day = nowTime.getDate(); nowTime = new Date(the_year,the_month,the_day); var thesecond = 24 * 60 * 60 *1000 ; var diffTime = (nowTime - checkDate)/thesecond;//计算天数 if (diffTime>0) { myreturn = ''; // } else if (diffTime==0) { myreturn = '今天'; } else { diffTime=0-diffTime; myreturn = '剩于'+diffTime+'天'; } //alert(myreturn); document.write(''+myreturn+'') }
模板中 <script>check_tdate('2008-12-25')</script>
|