实时显示今年还剩下几天几时几分几秒(js,练习Date的方法)

var date = new Date();
    var year = date.getFullYear();
    var newDate = new Date();
    newDate.setFullYear(year+1);
    newDate.setMonth(0,1);
    newDate.setHours(0,0,0);
    var itime = newDate.getTime()-date.getTime();
    var isecond = parseInt(itime/1000);
    var newDay = parseInt(isecond/24/60/60);
    var modeDay = isecond%(24*60*60);
    var newHour = parseInt(modeDay/60/60);
    var modeHour = modeDay%(60*60);
    var newMinute = parseInt(modeHour/60);
    var modeMinute = modeHour%60;
    var newSecond = parseInt(modeMinute);
    $(".time").text(year+"年还剩"+newDay+"天"+newHour+"时"+newMinute+"分"+newSecond+"秒");
    // document.write(year+"年还剩"+newDay+"天"+newHour+"时"+newMinute+"分"+newSecond+"秒"+"
");
  }
  window.setInterval(getTimeLeft,1000);

你可能感兴趣的:(实时显示今年还剩下几天几时几分几秒(js,练习Date的方法))