Parse milliseconds into a struct
$ go get -u github.com/fernandoporazzi/parse-ms
type ParsedMilliseconds
type ParsedMilliseconds struct {
Days int `json:"days"`
Hours int `json:"hours"`
Minutes int `json:"minutes"`
Seconds int `json:"seconds"`
Milliseconds int `json:"milliseconds"`
Microseconds int `json:"microseconds"`
Nanoseconds int `json:"nanoseconds"`
}
func Parse
func Parse(m float64) ParsedMilliseconds
Parse returns a struct of type ParsedMilliseconds
based on the given float64
input.
package main
import (
"encoding/json"
"fmt"
parsems "github.com/fernandoporazzi/parse-ms"
)
func main() {
// struct output
fmt.Println(parsems.Parse(60500.345678))
// json output
js, _ := json.Marshal(parsems.Parse(60500.345678))
fmt.Println(string(js))
}
- pretty-milliseconds - Convert milliseconds to a human readable string: 1337000000 โ 15d 11h 23m 20s