import ( "fmt" "time" ) func main() { duration := 5 * time.Second time.Sleep(duration) fmt.Println("Slept for 5 seconds") }
import ( "fmt" "time" ) func main() { t1 := time.Now() t2 := t1.Add(2 * time.Second) fmt.Println(t1) // current time fmt.Println(t2) // current time plus 2 seconds }In this example, we use the time.Now function to get the current time. We then use the Add method with the time.Second constant to add 2 seconds to the current time. The resulting time value is printed to the console. Package library: "time"