Import the time package and call its functions to handle durations, timers, and timestamps.
package main
import (
"fmt"
"time"
)
func main() {
// Get current time
now := time.Now()
fmt.Println(now)
// Sleep for 2 seconds
time.Sleep(2 * time.Second)
// Create a timer that fires in 1 second
timer := time.NewTimer(1 * time.Second)
<-timer.C
fmt.Println("Timer fired")
// Calculate duration
duration := time.Since(now)
fmt.Println(duration)
}