相关疑难解决方法(0)

如何获取JavaScript中两个日期之间的天数?

如何获取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)

javascript date

383
推荐指数
21
解决办法
45万
查看次数

Days/Weeks ago from specific date with Moment.js

I work with moment.js and I have 3 different dates, e.g.

  • 30.07.2018
  • 12.06.2018
  • 10.05.2018

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)

javascript jquery date momentjs

1
推荐指数
2
解决办法
2769
查看次数

标签 统计

date ×2

javascript ×2

jquery ×1

momentjs ×1