How to format time in Go

September 25, 2021 1 min read

Formatting time in go can be quite tricky, luckily there is a handy library called go-humanize that makes formatting time much easier.

Add the library to your project with the command below.

go install

Use the library by passing a time instace to the humanize.Time function. The output will be a nicely formatted date string in the form of 7 {unit} ago. See the example snippet below to learn about the usage.

package main

import (


func main() {
    t := time.Now()


Subscribe to not miss out on new content.

Keep up with things amazing things happening in technology, business, software, and the web.

You will never receive spam and you can unsubscribe at any time.
Mykolas Krupauskas

Written by Mykolas Krupauskas. A passionate software developer from Lithuania, currently situated in the Netherlands. Helping people create value with technology.