Time duration to string 2h instead 2h0m0s
问题 The default time.Duration String method formats the duration with adding 0s for minutes and 0m0s for hours. Is there function that I can use that will produce 5m instead 5m0s and 2h instead 2h0m0s ... or I have to implement my own? 回答1: Foreword: I released this utility in github.com/icza/gox, see timex.ShortDuration(). Not in the standard library, but it's really easy to create one: func shortDur(d time.Duration) string { s := d.String() if strings.HasSuffix(s, "m0s") { s = s[:len(s)-2] } if