How do I get the difference between two Dates in JavaScript?

前端 未结 16 2394
北海茫月
北海茫月 2020-11-22 03:03

I\'m creating an application which lets you define events with a time frame. I want to automatically fill in the end date when the user selects or changes the start date.

16条回答
  •  梦毁少年i
    2020-11-22 03:58

    function checkdate() {
        var indate = new Date()
        indate.setDate(dat)
        indate.setMonth(mon - 1)
        indate.setFullYear(year)
    
        var one_day = 1000 * 60 * 60 * 24
        var diff = Math.ceil((indate.getTime() - now.getTime()) / (one_day))
        var str = diff + " days are remaining.."
        document.getElementById('print').innerHTML = str.fontcolor('blue')
    }
    

提交回复
热议问题