如何获取JavaScript中两个日期之间的天数?例如,在输入框中给出两个日期:
<input id="first" value="1/1/2000"/>
<input id="second" value="1/1/2001"/>
<script>
alert(datediff("day", first, second)); // what goes here?
</script>
Run Code Online (Sandbox Code Playgroud) I work with moment.js and I have 3 different dates, e.g.
I now try to get the difference in days from these dates until today (if it is less then 7 days ago) or the weeks until today (if it more than 7 days ago) and place it in several spans.
UPDATE thanks Thomas!
I got:
$(document).ready(function(){
$('.timestamp').html((index, html) => {
let date = moment(html, "DD.MM.YYYY HH:mm", true),
now = moment(),
days = Math.floor(Math.abs(date - now) / …Run Code Online (Sandbox Code Playgroud)