我要计算距离奥运还有多少天,用javascript怎么弄?

解决方案 »

  1.   

    <script   language="vbScript">   
      birthday="2008-08-08"   
      msgbox(datediff("d",now,cdate(birthday)))   
      </script>
      

  2.   

      today = new Date();//申明一个时间对象
       intDate = today.getDate();//返回当前的天日期
       intHours = today.getHours();//返回当前小时
       intMinutes = today.getMinutes();//分钟
       intSeconds = today.getSeconds();//秒
       intMonth = today.getMonth()+1 ;//月加1
       intYear = today.getYear();//返回年
      

  3.   

    <input name="Input" id="time" style="border:none; color:#FF0000" value="-15314325" readonly>
                  <script language=JavaScript>
                  var tt="<%# etime(DataBinder.Eval(Container.DataItem,"etime").ToString().Trim())%>";
                  DateTime = new Array(); 
     DateTime = tt.split("-");
     var year = DateTime[0];
     var month = DateTime[1];
     var day = DateTime[2];
     var hour = DateTime[3];
     var minitue = DateTime[4];
     var second = DateTime[5];
     
     
     var Time = new Date(year,month - 1,day,hour,minitue,second); 
    var auctionDate = -15314325;
    var startTime = (new Date("2009/1/2")).getTime();
    var Temp;
    var timerID = null;
    var timerRunning = false;
    function showtime(){
    now = new Date();
    var ts=parseInt((Time.getTime()-now.getTime())/1000)+auctionDate;
    var dateLeft = 0;
    var hourLeft = 0;
    var minuteLeft = 0;
    var secondLeft = 0;
    if(ts < 0){
    ts = 0;
    CurHour = 0;
    CurMinute = 0;
    CurSecond = 0;}
    else {
    dateLeft =parseInt(ts/86400);
    ts = ts - dateLeft * 86400;
    hourLeft = parseInt(ts/3600);
    ts = ts - hourLeft * 3600;
    minuteLeft = parseInt(ts/60);
    secondLeft = ts - minuteLeft * 60;}
    if(hourLeft < 10) hourLeft = '0' +hourLeft;
    if(minuteLeft < 10) minuteLeft = '0' +minuteLeft;
    if(secondLeft<10) secondLeft='0'+secondLeft;
    if( dateLeft > 0 )
    dateLeft = dateLeft + "天" ;
    else
    dateLeft = "";
    if( hourLeft > 0 )
    hourLeft = hourLeft + "小时" ;
    else{
    if( dateLeft != "" )
    hourLeft = "00小时";
    else
    hourLeft = "";}
    if( minuteLeft > 0 )
    minuteLeft = minuteLeft + "分钟" ;
    else{
    if( dateLeft !="" || hourLeft != "")
    minuteLeft = "00分钟";
    else
    minuteLeft = "";}
    if( secondLeft > 0 )
    secondLeft = secondLeft + "秒" ;
    else{
    if( dateLeft !="" || hourLeft != "" || minuteLeft != "")
    secondLeft = "00秒";
    else
    secondLeft = "";}
    //if (dateLeft == '') {
    Temp=dateLeft+hourLeft+minuteLeft+secondLeft ;
    //}else {
    //Temp=dateLeft+hourLeft;}
    if(dateLeft <=0 && hourLeft<=0 && minuteLeft<=0 && secondLeft <=0){
    Temp = "结束";
    stopclock();}
    if (document.getElementById('time')) document.getElementById('time').value=Temp;
    timerID = setTimeout("showtime()",1000);
    timerRunning = true;}
    var timerID = null;
    var timerRunning = false;
    function stopclock(){
    if(timerRunning)
    clearTimeout(timerID);
    timerRunning = false;}
    function macauclock(){
    stopclock();
    showtime();}
    function onloadall(){
    macauclock();
    try{
    initprovcity(); }
    catch(e){
    }}
    try{
    onload=onloadall();}
    catch(e){}
      </script>
      

  4.   

    <script type="text/javascript" language="javascript">
    function DateDiff(interval,date1,date2){
     var long = date2.getTime() - date1.getTime(); //相差毫秒
     switch(interval.toLowerCase()){
      case "y": return parseInt(date2.getFullYear() - date1.getFullYear());
      case "m": return parseInt((date2.getFullYear() - date1.getFullYear())*12 + (date2.getMonth()-date1.getMonth()));
      case "d": return parseInt(long/1000/60/60/24);
      case "w": return parseInt(long/1000/60/60/24/7);
      case "h": return parseInt(long/1000/60/60);
      case "n": return parseInt(long/1000/60);
      case "s": return parseInt(long/1000);
      case "l": return parseInt(long);
     }
    }
    alert(DateDiff("d",new Date(),new Date(2008,8,8)));
    </script>
      

  5.   

    alert(距离奥运还有"<%=(new DateTime(2008, 8, 8) - DateTime.Now).Days%>"天);
      

  6.   

    忘加引号了。
    :)
    alert("距离奥运还有"+ " <%=(new DateTime(2008, 8, 8) - DateTime.Now).Days%>" + "天");
      

  7.   

    引用 2 楼 fphuang 的回复:today = new Date();//申明一个时间对象 
    intDate = today.getDate();//返回当前的天日期 
    intHours = today.getHours();//返回当前小时 
    intMinutes = today.getMinutes();//分钟 
    intSeconds = today.getSeconds();//秒 
    intMonth = today.getMonth()+1 ;//月加1 
    intYear = today.getYear();//返回年