Get Date and Time in Golang

You need to import the “time” package in your Go script to work with date and time. As an example use below script. I have also included fmt package to show formatted output on your screen.

For testing copy above code in a go script and Run application on your system using Golang. The result will be like below

Get Formatted Date and Time

It uses a predefined layout to format the date and time. The reference time used in the layouts is the specific time: “Mon Jan 2 15:04:05 MST 2006“.

Execute above program using Golang and see output: