Golang library to create human-readable US English strings from time.Duration instances.
go get github.com/BenJetson/humantime
import "github.com/BenJetson/humantime"
import (
"fmt"
"time"
"github.com/BenJetson/humantime"
)
func main() {
t := time.Now()
time.Sleep(5 * time.Second)
fmt.Println(humantime.Since(t)) // just now
time.Sleep(30 * time.Second)
fmt.Println(humantime.Since(t)) // seconds ago
time.Sleep(25 * time.Second)
fmt.Println(humantime.Since(t)) // a minute ago
time.Sleep(240 * time.Second)
fmt.Println(humantime.Since(t)) // 5 minutes ago
}
import (
"fmt"
"time"
"github.com/BenJetson/humantime"
)
func main() {
var d time.Duration
d, _ = time.ParseDuration("5s")
fmt.Println(humantime.Since(d)) // just now
d, _ = time.ParseDuration("25s")
fmt.Println(humantime.Since(d)) // seconds ago
d, _ = time.ParseDuration("60s")
fmt.Println(humantime.Since(d)) // a minute ago
d, _ = time.ParseDuration("5m")
fmt.Println(humantime.Since(d)) // 5 minutes ago
}