Format time duration?


I use this in main.go:

start := time.Now()
// Do something
fmt.Printf("Execution time: %s", time.Since(start))

And the output is normally:

Execution time: 1.5994525s

How do I reformat this output to:

Execution time: 1.60 s

-> Rounding to two decimal places after the dot, a space, “s”?

Got it…

fmt.Printf("Execution time: %.2f s", time.Now().Sub(start).Seconds())

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.