Format DateTime in Golang

Create new folder named src. In src folder, create new file named main.go as below:

package main

import (
	"fmt"
	"time"
)

func main() {
	today := time.Now()
	fmt.Println("Today: ", today.Format("02/01/2006 15:04:05"))

	str := "27/12/2018"
	date, error := time.Parse("02/01/2006", str)
	if error != nil {
		fmt.Println(error)
	} else {
		fmt.Println(date.Format("2006-01-02"))
	}
}




Open Terminal windows in Visual Studio Code and run command line: go run main.go

Today: 31/03/2019 13:25:49
2018-12-27