How to get time difference between two timestamps in seconds with jQuery?

前端 未结 5 564
猫巷女王i
猫巷女王i 2020-12-15 08:16

I want to display x seconds ago based on a MySQL Timestamp.

I found the plugin called timeago

But I cannot find a way to make it display only se

5条回答
  •  再見小時候
    2020-12-15 08:34

    jQuery is just a JavaScript library so JavaScript will just work within your jQuery script:

    // 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 milliseconds
    var timePassedInMilliseconds = (currentMiliseconds-oneDateMiliseconds)/1000;
    alert(timePassedInMilliseconds);
    

提交回复
热议问题