How do i change time format from minutes to hours+minutes on javascript

Hello there, ok i am just a beginner and when it comes to javascript i am a bit slow on understanding how it works very confusing but fun at the same time.
I have a script which is fare calculator so my problem for now that i have and want to change is the way it shows time only in minutes i want it to show if possible like this if its 1 hour or over 1 hour distance i would like to fix this to show 01:20.00 in 12 hour clock format can someone in the name of God help me out i am so lost with these codes.

I am going to post the whole code below so that way someone that knows what i mean can help me out because i cant seem to fix it.

It will be helpful to use a function that gives a 12 hour clock format to whatever seconds you give it. I’ve run up a quick function do to that:

function twelveHourClock(seconds) {
  function leadingZero(num) {
      if (num < 10) {
          return "0";
      return "";
  var hours = parseInt(seconds / 3600);
  var minutes = parseInt((seconds - hours * 3600) / 60);
  var seconds = seconds % 60;
  return leadingZero(hours) + hours +
      ":" + leadingZero(minutes) + minutes +
      ":" + leadingZero(seconds) + seconds;

The other thing that you will need, is to decide if the seconds are less than an hour, in which case you can show them as you currently are, or if they are an hour or more to use the 12 hour clock function instead.

var duration = results[j].duration.value;
if (duration < 60 * 60) {
} else {

Thanks Paul for your help, but where do i place this in my code.

What have you tried?

well the thing is that i do not understand much where to and how to place the line of code, i tried to paste that in my code and when i open the page and try to put an address nothing comes up like how google maps shows auto complete so it doesn’t function, do i need to add something to this code you added above?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.