Go Package time: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
=External=
=External=
 
* https://pkg.go.dev/strconv
* https://golang.org/pkg/time/


=Internal=
=Internal=
 
* [[Go_Language_Modularization#time|Standard library]]
* [[Go Concepts - Standard Library#Packages|Standard Library]]


=Overview=
=Overview=

Revision as of 04:15, 23 August 2023

External

Internal

Overview

  • time.After returns a channel that after the given duration, will send current time on it. This can be used to implement a timeout with select.

time.Sleep()

Sleep pauses the current goroutine for at least the duration d. A negative or zero duration causes Sleep to return immediately:

import "time"
...
var secs int
secs = 10
time.Sleep(time.Duration(secs) * time.Second)

After(Duration)

The After() returns a channel that will provide a Time instance after the given duration elapses. Equivalent with NewTimer(d).C.