Making Time
Making time means declaring a variable that holds the time formatted in a specific way. Formatting time will be covered at the end of this chapter; so, for now, we will use the default formatting that is provided by Go. In this topic, we will be executing everything in the main()
function of our script, so the skeleton should look like this:
package main import "fmt" import "time" func main(){ Â Â //this is where the code goes. }
Let's look at our skeleton first and learn how to create and manipulate time variables. Our skeleton has the standard package main
definition that is necessary. We use the fmt
package to print the output to the console. Since we'll be using the time
module, we'll need to import that as well.
Whenever we issue go run <script>.go
, the main()
function gets called and executes whatever is declared in it.
One of the most common jobs for the time
module is to measure the duration of the execution...