0

I use the Duration im my dc.table from dc.js if i return d.Duration i'll get this format:
Wed Jan 03 1900 01:01:00 GMT+0100 (W. Europe Standard Time)

But i wanted to convert it in this form: 49:01:00. Then i wrote this code:

function (d) {return ((d.Duration.getHours() + (d.Duration.getDay()-1) * 24)+":"+ d.Duration.getMinutes() +":"+ d.Duration.getSeconds());}

And it worked bu i got this: 49:1:0 it would be better to have it like this 49:01:00 (With the zeros)

But i dont know how i can do this :/ I'm getting my Duration data from a database and they are always different

some Examples for my Duration :

    0:2:3 -> 00:02:03
    0:7:53 -> 00:07:53
   1:14:16 -> 01:14:16
   47:29:3 ->  47:29:30

I hope someone can help me :(

  • Check this : http://stackoverflow.com/a/6040556/2815635 – Niklesh Raut Jun 20 '16 at 14:10
  • you can't do that with the regular datetime object. that's for dates+times. There is no "hour 49" in a day, which means you'll never get anything beyond 23 for the hour output. hour 24 is already "tomorrow" – Marc B Jun 20 '16 at 14:10

1 Answers1

0

i hope my program can solve your problem.

    function convert(str) {
    var date = new Date(str),
    hour = ("0" + (date.getHours() + (date.getDay()-1) * 24)).slice(-2),
    min  = ("0" + date.getMinutes()).slice(-2),
    sec = ("0" + date.getSeconds()).slice(-2);
    return [ hour, min, sec ].join(":");
    }

and then in your table:

 function (d) {return (convert(d.Duration));}, ....
Shalomi90
  • 736
  • 4
  • 9
  • 33