Go Language - Get Current Date and Time
Hello everyone, today we are going to learn how to get the current date and time in Go Language.
We need to import the “time” package in our Go script to work with date and time.
Go Program to find current Date and Time:
package main
import ( "fmt" "time")
func main() {
dt := time.Now()
fmt.Println(dt.String())
//Formatted Date and Time
//Format MM/DD/YYYY fmt.Println(dt.Format("01/02/2006"))
//Format MM-DD-YYYY fmt.Println(dt.Format("01-02-2006"))
//Format MM.DD.YYYY fmt.Println(dt.Format("01.02.2006"))
//Format MM-DD-YYYY hh:mm:ss fmt.Println(dt.Format("01-02-2006 15:04:05"))
//With ShortWeek Day fmt.Println(dt.Format("01-02-2006 Mon"))
//With weekday (Monday) fmt.Println(dt.Format("01-02-2006 15:04:05 Monday"))
//Include micro seconds fmt.Println(dt.Format("01-02-2006 15:04:05.000000"))
//Include nano seconds fmt.Println(dt.Format("01/02/2006 15:04:05.000000000"))}