JS案例:计算自己活了多少天
来自CloudWiki
<!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>