From the course: Learning Go
Unlock this course with a free trial
Join today to access over 24,200 courses taught by industry experts.
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 encapsulates everything you need for both dates and times, including math operations, time zone management, and so on. To demonstrate this I'll add the time package to my import block and then down here in the main function, I'll create a variable that I'll just call n, for now, and I'll get that value from time.Now a function that's a member of that package. And then I'll output the string, I recorded this video at and I'll pass in n. And when I run the code, I get a long string, a timestamp, that includes the current date, time, and time zone. Now I can also create my own explicit date/time values. This time I'll create a variable called t and I'll use time.Date. This function requires a year, a month, a day, an hour, a minute, a second, and a nanosecond, and something called a location. I'll pass in a…
Contents
-
-
-
-
Explore Go's variable types3m 16s
-
(Locked)
Declare and initialize variables5m 55s
-
(Locked)
Get input from the console3m 22s
-
(Locked)
Convert string inputs to other types4m 10s
-
(Locked)
Use math operators2m 3s
-
(Locked)
Use the math package5m 20s
-
(Locked)
Work with dates and times3m 50s
-
(Locked)
Solution: Create a simple calculator app2m 26s
-
-
-
-
-
-