Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有以下 Go 代码用于捕获经过的时间:
import ( "time" ) start := time.Now() ... end := time.Since(start) log.Printf("Elapsed Time: %s", end)
其输出为:
2019/10/26 13:22:53 Elapsed Time : 41.867µs
我希望输出简单:
Elapsed Time : 41.867µs
不确定如何抑制时间包默认数据/时钟时间输出。
要在没有日期和时间的情况下记录,请清除日期和时间标志:
log.SetFlags(log.Flags() &^ (log.Ldate | log.Ltime))
因为默认标志是(log.Ldate | log.Ltime),所以以下也适用:
(log.Ldate | log.Ltime)
log.SetFlags(0)