简体   繁体   English

JavaScript中的年龄计算器,具有运行时钟,无月,日或秒

[英]age calculator in javascript with running clock and NO months, days or seconds

There are many age calculators in js online, only all of them with months and days. 在线js中有很多年龄计算器,只有全部都有数月和数天。

I'm looking for something thats saying 31.5345343543 years old with a running clock (on 10ths of seconds), running from a birth date and time. 我正在寻找的东西说的是31.5345343543岁,带有运行时钟(以十分之一秒为单位),从出生日期和时间开始运行。 I know how to do it in php, but with php you can't make it a running clock :( And my JS just isn't good enough to do both.. 我知道如何在php中执行此操作,但是使用php时,您无法使其处于运行状态:(而且我的JS不足以同时实现这两个功能。

This is what I tried to far (took code from a running countdowntimer): 这就是我试图做到的(从正在运行的countdowntimer中获取代码):

<script>
var start = new Date('09/15/1982 03:29 PM');
var timer;

function age() {
    var now = new Date();
    var distance = now.getTime()-start.getTime();
    document.getElementById('age').innerHTML = (distance / 3155692600); // seconds in a year, times 100 to get the . right. 
}

timer = setInterval(age, 1);
</script>
<div id="age"></div>

Got it! 得到它了!

<script>
var start = new Date('09/15/1982 03:29 PM');
var timer;

function age() {
    var now = new Date();
    var age = now.getTime()-start.getTime();
    var year = (age / 31556926000); // seconds in a year * 1000
    document.getElementById('age').innerHTML = year.toFixed(9);
}

timer = setInterval(age, 1);
</script>
<div id="age"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM