Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use javascript to calculate how many days it has been since birth?

Shulou Source: shulou.com Published: 2022-05-31 11:52:11 10月02日 Update

This article mainly explains "how to use javascript to calculate the number of days since birth". Interested friends might as well take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use javascript to calculate how many days it has been since you were born.

How javascript calculates how many days you live: first define your birthday; then use the "parseInt ((today.getTime ()-birthday.getTime ()) / (1000 days 3600 days 24);" method to calculate how many days you live.

This article operating environment: windows7 system, javascript1.8.5 version, DELL G3 computer

Javascript's method of figuring out how many days he lived

Calculate how many days you lived from birth to today, and how old you are this year.

The code is as follows:

Var birthday=new Date ("1996-06-21"); / / define your birthday var today=new Date (); / / getTime () returns the number of milliseconds since January 1, 1970. / / 1 second = 1000 milliseconds 3600 hours 1 hour * 1 minute 24 hours var time=parseInt ((today.getTime ()-birthday.getTime ()) / (1000 seconds 3600 seconds 24)); var year=Math.round (time/365); / / round () method can round a number to the nearest integer. [xss_clean] ("live from birth to today" + time+ "days"); [xss_clean] ("this year" + year+ "year"). At this point, I believe you have a deeper understanding of "how to use javascript to calculate how many days you have been born to now". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Methods content hours birthdays learning practical deeper code interest practicality practical simple operation numbers integers more friends environment computers systems websites Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Redmi Docker OPPO Reno NVidia