npm i timemilliconverter
const timestring = require('timemilliconverter')
let str = '1h 15m'
let time = timestring.getTimeString(str)
console.log(time) // will log 4500
By default the returned time value from getTimeString
will be in milliseconds.
The time string can contain as many time groups as needed:
const timestring = require('timemilliconverter')
let str = '1d 3h 25m 18s'
let time = timestring.getTimeString(str)
console.log(time) // will log 98718
and can be as messy as you like:
const timestring = require('timemilliconverter')
let str = '1 d 3HOurS 25 min 1 8s'
let time = timestring.getTimeString(str)
console.log(time) // will log 98718
getTimeString
will parse the following keywords into time values:
ms, milli, millisecond, milliseconds
- will parse to millisecondss, sec, secs, second, seconds
- will parse to secondsm, min, mins, minute, minutes
- will parse to minutesh, hr, hrs, hour, hours
- will parse to hoursd, day, days
- will parse to daysw, week, weeks
- will parse to weeksmon, mth, mths, month, months
- will parse to monthsy, yr, yrs, year, years
- will parse to years
Keywords can be used interchangeably:
const timestring = require('timemilliconverter')
let str = '1day 15h 20minutes 15s'
let time = timestring.getTimeString(str)
console.log(time) // will log 141615
By default the return time value will be in milliseconds. This can be changed by passing one of the following strings as an argument to getTimeString
:
ms
- Millisecondss
- Secondsm
- Minutesh
- Hoursd
- Daysw
- Weeksmth
- Monthsy
- Years
const timestring = require('timemilliconverter')
let str = '22h 16m'
let hours = timestring.getTimeString(str, 'h')
let days = timestring.getTimeString(str, 'd')
let weeks = timestring.getTimeString(str, 'w')
console.log(hours) // will log 22.266666666666666
console.log(days) // will log 0.9277777777777778
console.log(weeks) // will log 0.13253968253968254