Return elapsed time since a given time.
time.Since returns the time elapsed since t. It is shorthand for time.Now().Sub(t) and uses the monotonic clock reading if available for accurate measurement.
time.Since is commonly used for measuring execution time, benchmarking, and logging elapsed durations.
Because time.Since uses the monotonic clock, it returns accurate results even if the system wall clock is adjusted during the measurement.
| Name | Description | Optional |
|---|---|---|
t |
The starting time to measure from. | No |
start := time.Now()
time.Sleep(100 * time.Millisecond)
fmt.Println(time.Since(start)) // ~100ms