-4

I have bunch of different values (seconds) passed as props to a child and i want do convert it so i could render hour,minutes,seconds Whats the best way to do it?

  • What have you got so far? Javascript has modulo operator `%` for remainders and `Math.floor` for floor division. There's nothing react specific about this problem. – Håken Lid Jun 02 '19 at 15:00
  • Possible duplicate of [How to convert seconds to minutes and hours in javascript](https://stackoverflow.com/questions/37096367/how-to-convert-seconds-to-minutes-and-hours-in-javascript) – Håken Lid Jun 02 '19 at 15:02
  • Im sorry but i dont think it is duplicate i know how do convert it in js i didn't understand properly how to apply it in react or whats the best way. – Kristo Palu Jun 02 '19 at 15:14

2 Answers2

1

I think you can find the solution in here or here or here ...

function secondsToHms(d) {
    d = Number(d);
    var h = Math.floor(d / 3600);
    var m = Math.floor(d % 3600 / 60);
    var s = Math.floor(d % 3600 % 60);

    var hDisplay = h > 0 ? h + (h == 1 ? " hour, " : " hours, ") : "";
    var mDisplay = m > 0 ? m + (m == 1 ? " minute, " : " minutes, ") : "";
    var sDisplay = s > 0 ? s + (s == 1 ? " second" : " seconds") : "";
    return hDisplay + mDisplay + sDisplay; 
}
noam621
  • 2,766
  • 1
  • 16
  • 26
0
minutes = this.props.seconds/60;
hours = this.props.seconds/3600;

Have you tried this?

Sam Chahine
  • 530
  • 1
  • 17
  • 52