当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 用js计算自己从出生到现在生活了多长时间(x天零x小时零x分钟零x秒) 初学者,大家多多包涵,有不足的地方请多包涵。

用js计算自己从出生到现在生活了多长时间(x天零x小时零x分钟零x秒) 初学者,大家多多包涵,有不足的地方请多包涵。

2019年04月07日  | 移动技术网IT编程  | 我要评论
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
  <script>
    var now = new date;
    var bir = new date(1995,09,24,08,50,10);  //在这里按照这个格式输入自己生日:年月日时分秒
    console.log(bir.gettime() + '<br>');
    console.log(now.gettime() + '<br>');
    var cha = now - bir;
    console.log(cha + '<br>')
    var date = cha / 86400000;
    document.write('出生到现在你已经生活了' + parseint(date) + '天零');
    var hours1 = (cha % 86400000) / 3600000;
    document.write(parseint(hours1) + '小时零');
    var minutes1 = (cha % 86400000 % 3600000) / 60000;
    document.write(parseint(minutes1) + '分钟零');
    var second1 = (cha % 86400000 % 3600000 % 60000)/ 1000;
    document.write(parseint(second1) + '秒');
  </script>
<title>document</title>
</head>
<body>
</body>
</html>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网