function runTime var d = new Date str = ; BirthDay = new Date2022-1-3; today = new Date; timeold = todaygetTime - BirthDaygetTime; sectimeold = timeold 1000 secondsold = Mathfloors
The function runTime() calculates the time elapsed since a specific date (in this case, January 3, 2022) and returns a string representing the number of days, hours, minutes, and seconds that have passed.
Here's how the function works:
- It creates a new
Dateobject for the current date and time (stored in thedvariable). - It creates a new
Dateobject for the specified birthdate (stored in theBirthDayvariable). - It subtracts the birthdate from the current date to get the time difference in milliseconds (stored in the
timeoldvariable). - It calculates the number of seconds that have passed by dividing the time difference by 1000 (stored in the
secondsoldvariable). - It calculates the number of days that have passed by dividing the time difference by the number of milliseconds in a day (stored in the
e_daysoldvariable). - It calculates the number of years that have passed by dividing the time difference by the number of milliseconds in a year (stored in the
e_yearsoldvariable). - It rounds down the values of
e_daysoldande_yearsoldto get whole numbers (stored in thedaysoldandyearsoldvariables). - It concatenates the number of days, hours, minutes, and seconds into a string (stored in the
strvariable). - It returns the string.
Note: The code currently only returns the number of days, hours, minutes, and seconds. If you want to include the number of years, you can uncomment the line //str = yearsold + "年"; by removing the double slashes at the beginning of the line
原文地址: https://www.cveoy.top/t/topic/h2y0 著作权归作者所有。请勿转载和采集!