# Go's time.Duration Type Unravelled

DevFeed: [Go's time.Duration Type Unravelled](<https://devfeed.tech/articles/go-s-time-duration-type-unravelled-22048.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2013/06/gos-duration-type-unravelled.html>)

Published: 2013-06-11T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [Go Language](<https://devfeed.tech/topics/go-language.md>), [Library](<https://devfeed.tech/topics/library.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [ardan-labs](<https://devfeed.tech/tags/ardan-labs.md>), [blog](<https://devfeed.tech/tags/blog.md>), [code](<https://devfeed.tech/tags/code.md>), [compare](<https://devfeed.tech/tags/compare.md>), [go](<https://devfeed.tech/tags/go.md>), [go-programming](<https://devfeed.tech/tags/go-programming.md>), [golang](<https://devfeed.tech/tags/golang.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [library](<https://devfeed.tech/tags/library.md>), [programming](<https://devfeed.tech/tags/programming.md>), [standard-library](<https://devfeed.tech/tags/standard-library.md>)

## AI overview

This tutorial explains Go's time.Duration type, including its nanosecond base unit, predefined time constants, and safer ways to create and compare durations. It shows why directly converting a duration to int64 can produce unexpected values.

## Source excerpt

I have been struggling with using the Time package that comes in the Go standard library. My struggles have come from two pieces of functionality. First, trying to capture the number of milliseconds between two different time periods. Second, comparing that duration in milliseconds against a pre-defined time span. It sounds like a no brainier but like I said, I have been struggling. In the Time package there is a custom type called Duration and a set of helper constants: