Go Time and Duration

GoGoBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

This challenge aims to test your understanding of Go's time and duration support.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL go(("`Go`")) -.-> go/AdvancedTopicsGroup(["`Advanced Topics`"]) go/AdvancedTopicsGroup -.-> go/time("`Time`") subgraph Lab Skills go/time -.-> lab-15442{{"`Go Time and Duration`"}} end

Time

The code below contains examples of how to work with time and duration in Go. However, some parts of the code are missing. Your task is to complete the code to make it work as expected.

Requirements

  • Basic knowledge of Go programming language.
  • Familiarity with Go's time and duration support.

Example

$ go run time.go
2012-10-31 15:50:13.793654 +0000 UTC
2009-11-17 20:34:58.651387237 +0000 UTC
2009
November
17
20
34
58
651387237
UTC
Tuesday
true
false
false
25891h15m15.142266763s
25891.25420618521
1.5534752523711128e+06
9.320851514226677e+07
93208515142266763
2012-10-31 15:50:13.793654 +0000 UTC
2006-12-05 01:19:43.509120474 +0000 UTC

## Next we'll look at the related idea of time relative to
## the Unix epoch.

Summary

This challenge tested your ability to work with Go's time and duration support. You learned how to extract various components of a time value, compare two times, compute the length of a duration, and advance a time by a given duration.

Other Go Tutorials you may like