项目作者: ryanfarber

项目描述 :
converts a string containing an amount of time to other units of time
高级语言: JavaScript
项目地址: git://github.com/ryanfarber/time-string-parser.git
创建时间: 2020-09-11T07:36:42Z
项目社区:https://github.com/ryanfarber/time-string-parser

开源协议:

下载


time-string-parser

Converts an arbitrary string of an amount of time to other units of time. You can use any of the conventional spellings/abbreviations of time units.

Ex: 10 weeks/wks, 14 hours/hrs/H

The function takes 2 arguments:

string: your time string

number: number of digits to appear after decimal point (optional, default is 2)

example

  1. var timestring = require("time-string-parser")
  2. console.log(timestring("8 yrs", 0).months)
  3. // 97
  4. console.log(timestring("69 months", 0).weeks)
  5. // 296
  6. console.log(timestring("420 week", 0).days)
  7. // 2940
  8. console.log(timestring("3.14159 days", 2).hours)
  9. // 75.40
  10. console.log(timestring("1024 hrs", 0).mins)
  11. // 61440
  12. console.log(timestring("5040 minutes", 0).secs)
  13. // 302400
  14. console.log(timestring("8128 seconds", 0).ms)
  15. // 8128000
  16. console.log(timestring("299792458 millis", 10).years)
  17. // 0.0095063565