Learn about Program to print current date-time using Format() function in Golang in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Contents
Program to print current date-time using Format() function in Golang
// Golang program to print current date-time in
// different formats using Format() function
package main
import "fmt"
import "time"
func main() {
dateTime := time.Now()
fmt.Println(dateTime.Format("01-02-2006 15:04:05.000000000"))
fmt.Println(dateTime.Format("01-02-2006"))
fmt.Println(dateTime.Format("01-02-2006 15:04:05 Mon"))
fmt.Println(dateTime.Format("01-02-2006 15:04:05"))
fmt.Println(dateTime.Format("01-02-2006 15:04:05.000000"))
fmt.Println(dateTime.Format("01-02-2006 15:04:05 Monday"))
}
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Codes :
Program to get current date and time in Golang
Program to get the day of the specified date in Golang