find the current date and time in go

To find the current date and time in Go, you can use the time.Now() function. This function returns the current local time.Time value. Here's an example code snippet to print the current date and time in Go:

main.go
package main

import (
	"fmt"
	"time"
)

func main() {
	currentTime := time.Now()
	fmt.Println("Current date and time:", currentTime)
}
136 chars
12 lines

This will output the current date and time in the following format:

main.go
Current date and time: 2021-10-04 13:45:12.123456 +0530 IST
60 chars
2 lines

You can also format the time value to obtain the date or time in a specific format using the time.Format() method.

related categories

gistlibby LogSnag