How to suppress date when printing elapsed time

66 Views Asked by At

I have the following Go code used to capture elapsed time:

import (
 "time"
)

start := time.Now()
...
end := time.Since(start)
log.Printf("Elapsed Time:  %s", end)

The output of which is:

2019/10/26 13:22:53 Elapsed Time :  41.867µs

I would like the output to be simply:

Elapsed Time :  41.867µs

Not sure how to supress the time packages default data/clock time output.

1

There are 1 best solutions below

0
On BEST ANSWER

To log without a date and time, clear the date and time flags:

log.SetFlags(log.Flags() &^ (log.Ldate | log.Ltime))

Because the default flags are (log.Ldate | log.Ltime), the following also works:

log.SetFlags(0)