Check time difference in Javascript

后端 未结 18 1146
梦毁少年i
梦毁少年i 2020-11-22 04:27

How would you check time difference from two text-boxes in Javascript?

18条回答
  •  名媛妹妹
    2020-11-22 04:55

    I would use just getTime(); and for example Date.now() to return difference in milliseconds:

     //specified date:
    
    var oneDate = new Date("November 02, 2017 06:00:00");
    
    //number of milliseconds since midnight Jan 1 1970 till specified date
    
    var oneDateMiliseconds = oneDate.getTime();
    
    ////number of milliseconds since midnight Jan 1 1970 till now
    
    var currentMiliseconds = Date.now(); 
    
    //return time difference in miliseconds
    
    alert(currentMiliseconds-oneDateMiliseconds);
    

提交回复
热议问题