How to Get Current time in Golang?
Last Updated :
21 Apr, 2020
With the help of time.Now()
function, we can get the current time in Golang by importing time module.
Syntax: time.Now()
Return: Return current date and time.
Example #1: In this example, we can see that by using time.Now()
function, we are able to get the current date and time.
package main
import "fmt"
import "time"
func main() {
dt := time .Now()
fmt.Println( "Current date and time is: " , dt.String())
}
|
Output :
Current date and time is: 2009-11-10 23:00:00 +0000 UTC m=+0.000000001
Example #2:
package main
import "fmt"
import "time"
func main() {
dt := time .Now()
fmt.Println(dt.Format( "01-02-2006 15:04:05" ))
}
|
Output:
11-10-2009 23:00:00
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...