From the course: Learning Go

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Work with dates and times

Work with dates and times - Go Tutorial

From the course: Learning Go

Work with dates and times

- [Instructor] Dates and times are managed in Go with the time package. A variable declared with the time type shown here in the documentation encapsulates everything you need for both dates and times, including math operations, time zones and so on. There are a few different functions you can use to create time objects. The date function lets you pass in specific information for the year, month, day, and so on. So I'll start with this file. I'll get rid of this line of code and I'm going to create a time object for the specific moment in time when the Go programming language was launched. I'll name this new variable t for time and I'll set it with time.date, and I'll pass in first the year, that was 2009, then the month, and I'll use a constant for that of time.November. Then the date, the hour, which is 23 for 11:00 PM Then the minutes, the seconds, and the nanoseconds, and then the time zone for which I'll use time.UTC. Then I'll display that time object with fmt.Printf. I'll use…

Contents