How can I convert milliseconds to “hhmmss” format using javascript?

前端 未结 6 2015
花落未央
花落未央 2021-01-18 02:11

I am using javascript Date object trying to convert millisecond to how many hour, minute and second it is.

I have the currentTime in milliseconds

var         


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-18 02:41

    var timediff = futureTime - currentTime
    long seconds = (long) (timediff / 1000) % 60 ;
    long minutes = (long) ((timediff / (1000*60)) % 60);
    long hours   = (long) ((timediff / (1000*60*60)) % 24);
    if(hours>0)
        time = hours+" hrs : "+minutes+" mins";
    else if(minutes>0)
        time = minutes+" mins";
    else if(seconds>0)
        time = seconds+" secs";
    

提交回复
热议问题