You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
446 B
Go

package utils
import (
"strings"
"time"
)
type timeUtils struct{}
func TimeUtils() *timeUtils {
return &timeUtils{}
}
// DurationString Duration转自定义String
func (tu timeUtils) DurationString(d time.Duration) string {
if d.Seconds() == 0 {
return "00:00:00"
}
s := d.String()
s = strings.ReplaceAll(s, "h", ":")
s = strings.ReplaceAll(s, "m", ":")
idx := strings.Index(s, ".")
if idx == -1 {
return s
}
return s[:idx]
}