Skip to content

Instantly share code, notes, and snippets.

@davidsharp
Created January 5, 2017 12:06
Show Gist options
  • Select an option

  • Save davidsharp/bfbb2fa3880de62be934f5df714fdf1a to your computer and use it in GitHub Desktop.

Select an option

Save davidsharp/bfbb2fa3880de62be934f5df714fdf1a to your computer and use it in GitHub Desktop.
Dirty conversion from 'HH:MM' format string to integer minutes and back again
const hhmmToMinutes = hhmm => hhmm.split(':').map((c,i)=>(i===0?parseInt(c)*60:parseInt(c))).reduce((a,b)=>(a+b),0)
const minutesToHhmm = min => (`${Math.floor(min/60)<10?0:''}${Math.floor(min/60)}:${min%60<10?0:''}${min%60}`)
// hhmmToMinutes('8:59') //539 (480+59)
// minutesToHhmm(539) //'08:59'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment