您好,欢迎来到源码搜藏!分享精神,快乐你我!提示:担心找不到本站?在百度搜索“源码搜藏”,网址永远不丢失!
  • 首 页
  • 在线工具
  • 当前位置:首页 > 网页特效 > 计算转换 >

    javaScript指定你的出生年月计算到现在过去了多少天、小时、秒

    时间:2014-05-23 08:41 来源:互联网 作者:源码搜藏 浏览:收藏 挑错 推荐 打印

    运行代码保存代码复制代码 提示:您可以先修改部分代码再运行,保存代码功能在Firefox下无效。
    • javaScript指定过去时间计算到现在过去了多少天、小时、秒,比如计算从你出生到目前为止,你已度过了多少天、多少小时、多少分钟、多少秒,计算出您的精彩人生!主要是练习用JS计算时间操作的,在平时,会有不少类似的求时间差的问题,但愿这个小小的JS特效可以为你提供帮助。
    • <script language="javascript">
      var biryear = prompt('请输入你的出生年份','1980');
      var birmonth = prompt('请输入你的出生月份','5');
      var birday = prompt('请输入你的出生日','30');
      var year = new Date();
      var getyear = year.getYear();
      TMonth = new Array('Jan','Feb','Mar','Apr','May','June','July','Aug','Sep','Oct','Nov','Dec');
      nowMonth = birmonth - 1;
      bmonth = TMonth[nowMonth];
      var timerid;
      var timerRunning = false;
      var today = new Date();
      var startday = new Date();
      var enday = new Date();
      var minPerDay = 0;
      var secsLeft = 0;
      var secsRound = 0;
      var secsRemain = 0;
      var minLeft = 0;
      var minRound = 0;
      var minRemain = 0;
      var timeRemain = 0;
      function showtime() 
      {
      startday = new Date(""+bmonth+" "+birday+", "+biryear+" 00:00 EDT");
      startday.setYear(""+biryear+"");
      today = new Date();
      secsPerDay = 1000 ;
      minPerDay = 60 * 1000 ;
      hoursPerDay = 60 * 60 * 1000;
      PerDay = 24 * 60 * 60 * 1000;
      secsLeft = (today.getTime() - startday.getTime()) / minPerDay;
      secsRound = Math.round(secsLeft);
      secsRemain = secsLeft - secsRound;
      secsRemain = (secsRemain < 0) ? secsRemain = 60 - ((secsRound - secsLeft) * 60) : secsRemain = (secsLeft - secsRound) * 60;
      secsRemain = Math.round(secsRemain);
      minLeft = ((today.getTime() - startday.getTime()) / hoursPerDay);
      minRound = Math.round(minLeft);
      minRemain = minLeft - minRound;
      minRemain = (minRemain < 0) ? minRemain = 60 - ((minRound - minLeft) * 60) : minRemain = ((minLeft - minRound) * 60);
      minRemain = Math.round(minRemain - 0.495);
      hoursLeft = ((today.getTime() - startday.getTime()) / PerDay);
      hoursRound = Math.round(hoursLeft);
      hoursRemain = hoursLeft - hoursRound;
      hoursRemain = (hoursRemain < 0) ? hoursRemain = 24 - ((hoursRound - hoursLeft) * 24)  : hoursRemain = ((hoursLeft - hoursRound) * 24);
      hoursRemain = Math.round(hoursRemain - 0.5);
      daysLeft = ((today.getTime() - startday.getTime()) / PerDay);
      daysLeft = (daysLeft - 0.5);
      daysRound = Math.round(daysLeft);
      daysRemain = daysRound;
      day_rem = " 天 >>> "
      hour_rem = " 小时 >>> "
      min_rem = " 分 >>> "
      sec_rem = " 秒"
      timeRemain = daysRemain + day_rem + hoursRemain + hour_rem + minRemain + min_rem + secsRemain + sec_rem;
      document.up.face.value = timeRemain;
      timerid = setTimeout("showtime()",1000);
      timerRunning = true;
      }
      </SCRIPT>      
    javaScript指定你的出生年月计算到现在过去了多少天、小时、秒由源码搜藏网整理,转载请注明出处http://www.codesocang.com/texiao/jisuanzhuanhuan/8021.html
    标签:网站源码