Previously, we imported a single package,
fmt. This package is useful but it is only one in a list of many included with Go.
The standard packages are so useful that you will often use multiple packages in each
Importing Multiple Packages
To import multiple packages, we can add multiple
import "package1" import "package2"
Or use a single
import with parentheses:
import ( "package1" "package2" )
We can also provide an alias to a package by specifying an alias name before the package name.
import ( p1 "package1" "package2" )
In the example above we’ve aliased
p1 and now we can call functions from
package1 by using
In main.go, we have our “Hello World” program set up.
import another package,
Assign an alias of
t to the
main, let’s use the
time package. Add the line:
This line will print the current time using both the
Note: the time printed will be UTC time zone.
Run the program using the command line. Look at the time printed out!