moment.js diff date formatting

后端 未结 2 1226
名媛妹妹
名媛妹妹 2021-02-13 05:51

I\'m using moment.js and want to calculate the difference between two timestamp,format them afterwards and display them in a div.

var diffTime = moment(13903101         


        
2条回答
  •  不要未来只要你来
    2021-02-13 06:26

    try this

    var diffTime = moment(moment(1390310146.791877).diff( 1390309386.271075)).format('H m s');
    

    it will output "5 30 0"

    Edit

    here is the simple way to get the difference. for this both the time should be in the same timezone.

    var a = moment(1390310146.791877);
    var b = moment(1390309386.271075);
    a.diff(b)//To get the difference in milliseconds
    a.diff(b,'seconds')//To get the difference in seconds
    a.diff(b,'minutes')//To get the difference in minutes 
    a.zone()//Get the timezone offset in minutes
    

    hope this helps.

提交回复
热议问题