Home > Web Front-end > JS Tutorial > body text

javaScript calculates the difference in days between two dates (sample code)_javascript skills

WBOY
Release: 2016-05-16 17:06:46
Original
1014 people have browsed it

1: Calculate the number of days between two dates

For example:
str1 = "2002-01-20"
str2 = "2002-10-11"
How to use JavaScript to calculate the number of days between str1 and str2?

Copy code The code is as follows:











The 100 above represents the date 100 days later, you can modify it. Date.getTime() in JS can only support dates after 1970.01.01; and the month is 0 - 11, which is a bit different, so avoid it. Of course you can also calculate dates after a specific date.
Copy code The code is as follows:


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template