This example shows how to display the current date and time in Golang.
The time package provides functionality for measuring and displaying time.
The Now function returns the current local time.
Go - Current Time Example
Let's create a file named "go_example.go" and add the following source code to it:
package main
import (
"fmt"
"time"
)
func main() {
now := time.Now()
fmt.Println("The current datetime is:", now)
}
Run the following command to execute the go_example.go file:
G:\GoLang\examples>go run go_example.go The current datetime is: 2021-06-21 17:09:07.3904122 +0530 IST m=+0.006439001