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

<!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>