time.NewTimer() Function in Golang With Examples Last Updated : 21 Apr, 2020 Comments Improve Suggest changes Like Article Like Report In Go language, time packages supplies functionality for determining as well as viewing time. The NewTimer() function in Go language is used to create a new Timer that will transmit the actual time on its channel at least after duration "d". Moreover, this function is defined under the time package. Here, you need to import the "time" package in order to use these functions. Syntax: func NewTimer(d Duration) *Timer Here, *Timer is a pointer to the Timer. Return Value: It returns a channel that notifies how long a timer will have to wait. Example 1: C // Golang program to illustrate the usage of // NewTimer() function // Including main package package main // Importing fmt and time import ( "fmt" "time" ) // Main function func main() { // Calling NewTimer method newtimer := time.NewTimer(5 * time.Second) // Notifying the channel <-newtimer.C // Printed after 5 seconds fmt.Println("Timer is inactivated") } Output: Timer is inactivated Here, the above output is printed after 5 seconds of running the code, as after that stated time the channel is being notified that the timer is inactivated. Example 2: C // Golang program to illustrate the usage of // NewTimer() function // Including main package package main // Importing fmt and time import ( "fmt" "time" ) // Main function func main() { // Calling NewTimer method newtimer := time.NewTimer(time.Second) // Notifying channel under go function go func() { <-newtimer.C // Printed when timer is fired fmt.Println("timer inactivated") }() // Calling stop method to stop the // timer before inactivation stoptimer := newtimer.Stop() // If the timer is stopped then the // below string is printed if stoptimer { fmt.Println("The timer is stopped!") } // Calling sleep method to stop the // execution at last time.Sleep(4 * time.Second) } Output: The timer is stopped! In the above method, the timer is being stopped before inactivating as here the stop method is being called to stop the timer. And at last, the program is exited using sleep method. Comment More infoAdvertise with us Next Article time.NewTimer() Function in Golang With Examples nidhi1352singh Follow Improve Article Tags : Go Language GoLang-time Similar Reads time.NewTicker() Function in Golang With Examples In Go language, time packages supplies functionality for determining as well as viewing time. The NewTicker() function in Go language is used to output a new Ticker that contains a channel in order to transmit the time with a period as stated by the duration parameter. It is helpful in setting the i 2 min read time.Time.In() Function in Golang with Examples In Go language, time packages supplies functionality for determining as well as viewing time. The In() function in Go language is used to find a copy of the stated "t" that represents the identical time instant, but along with the copy's location data that is set to "loc" for display uses. And if "l 2 min read time.Time.Minute() Function in Golang With Examples In Go language, time packages supplies functionality for determining as well as viewing time. The Time.Minute() function in Go language is used to find the minute offset within the stated hour that is provided by "t" and the range is [0, 59]. Moreover, this function is defined under the time package 2 min read time.Now() Function in Golang With Examples In Go language, time packages supplies functionality for determining as well as viewing time. The Now() function in Go language is used to find the current local time. Moreover, this function is defined under the time package. Here, you need to import the "time" package in order to use these functio 2 min read time.Time.String() Function in Golang With Examples In Go language, time packages supplies functionality for determining as well as viewing time. The Time.String() function in Go language is used to yield the time which is formatted with the help of the format string. Moreover, this function is defined under the time package. Here, you need to import 2 min read Like