How to convert minutes to hours/minutes and add various time values together using jQuery?

后端 未结 10 891
旧巷少年郎
旧巷少年郎 2020-12-07 13:03

There are a couple parts to this question. I am not opposed to using a jQuery plugin if anyone knows of one that will accomplish what I want done.

Q1 - How d

10条回答
  •  情歌与酒
    2020-12-07 13:36

    This code can be used with timezone

    javascript:

    let minToHm = (m) => {
      let h = Math.floor(m / 60);
      h += (h < 0) ? 1 : 0;
      let m2 = Math.abs(m % 60);
      m2 = (m2 < 10) ? '0' + m2 : m2;
      return (h < 0 ? '' : '+') + h + ':' + m2;
    }
    
    console.log(minToHm(210)) // "+3:30"
    console.log(minToHm(-210)) // "-3:30"
    console.log(minToHm(0)) // "+0:00"

    minToHm(210)
    "+3:30"
    
    minToHm(-210)
    "-3:30"
    
    minToHm(0)
    "+0:00"
    

提交回复
热议问题