小编Max*_*mpo的帖子

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 ×1

javascript ×1

jquery ×1

momentjs ×1