0

How to get current time HH: MM: SS in Audio JavaScript DOM?

I want to display audio object current time like HH: MM: SS in PureJS!

Example:
Example

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 1
    Does this answer your question? [Javascript/HTML5: get current time of audio tag](https://stackoverflow.com/questions/22501782/javascript-html5-get-current-time-of-audio-tag) – Heretic Monkey Mar 31 '21 at 18:51
  • Please read the question carefully..I'm looking for the current time display in the format HH: MM: SS! – Waled K. Fikrey Mar 31 '21 at 19:10
  • 2
    Then your question is a dupe of [Convert seconds to HH-MM-SS with JavaScript?](https://stackoverflow.com/q/1322732/215552) since `currentTime` returns the number of seconds. – Heretic Monkey Mar 31 '21 at 19:50
  • 3
    Please don't make more work for other people by vandalizing your posts. By posting on the Stack Exchange network, you've granted a non-revocable right, under the [CC BY-SA 4.0 license](//creativecommons.org/licenses/by-sa/4.0/), for Stack Exchange to distribute that content (i.e. regardless of your future choices). By Stack Exchange policy, the non-vandalized version of the post is the one which is distributed. Thus, any vandalism will be reverted. If you want to know more about deleting a post please see: [How does deleting work?](//meta.stackexchange.com/q/5221) – Dharman Oct 22 '21 at 10:44
  • I will point you out to the [docs for the Date object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTimeString). You can create a date object with current time and display the time. I'm not sure is that what you are trying to do, or if you are trying to display an audio playback controller displaying the elapsed and remaining time. For the latter you will need to provide a more detailed question – Roberto Langarica Mar 31 '21 at 18:48

1 Answers1

0
//// get current time 
myPlayer.addEventListener("timeupdate", function(){
    myRange.value  = myPlayer.currentTime;
    tt = "0";
    var Amin = Math.floor(myPlayer.currentTime/60);

    var Asec = Math.floor(myPlayer.currentTime - Amin * 60);

    if(Asec < 10){
        Asec = "0" + Asec;
    }
    if(Amin > 10){
        tt="";
    }
    currenttime.innerHTML = tt+Amin+":"+Asec;
});
Dharman
  • 30,962
  • 25
  • 85
  • 135