time.Now() Function in Golang With Examples
Last Updated :
21 Apr, 2020
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 functions.
Syntax:
func Now() Time
Return Value: It returns the current local time.
Example 1:
package main
import "fmt"
import "time"
func main() {
tm := time .Now()
fmt.Printf( "%s" , tm )
}
|
Output:
2020-04-09 11:24:14.785868848 +0000 UTC m=+0.000187421
Here, current time is returned in UTC.
Example 2:
package main
import "fmt"
import "time"
func main() {
tm := time .Now()
tm1 := time .Now()
fmt.Printf( "%s\n" , tm )
time .Sleep(10 * time .Second)
fmt.Printf( "%s" , tm1)
}
|
Output:
2020-04-09 11:37:59.087484568 +0000 UTC m=+0.000106559
2020-04-09 11:37:59.087484779 +0000 UTC m=+0.000106736
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...