Categorygithub.com/andanhm/go-prettytime
modulepackage
1.1.0
Repository: https://github.com/andanhm/go-prettytime.git
Documentation: pkg.go.dev

# README

Go Pretty Time

Go Report Card Build Status GoDoc CodeCov

Format Go date time in a pretty way. ex : just now, a minute ago, 2 hours ago , 3 minutes ago

Inspired by the John Resig Pretty Date plug-in for JQuery

prettytime.Format("2008-01-28T20:24:17Z") // => "2 hours ago"
prettytime.Format("2008-01-27T22:24:17Z") // => "Yesterday"
prettytime.Format("2008-01-26T22:24:17Z") // => "2 days ago"
prettytime.Format("2008-01-14T22:24:17Z") // => "2 weeks ago"

Install

go get github.com/andanhm/go-prettytime

Example

package main

import (
	"log"
	"time"

	"github.com/andanhm/go-prettytime"
)

const (
	layout = "2006-01-02T15:04:05Z"
)

func main() {
	t, err := time.Parse(layout, "2008-01-28T20:24:17Z")
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("%s \n", prettytime.Format(t))
}
// Output: 13 years ago

Contributions

Feel free to fork and add features, fix bugs and your pull request is more than welcome ❤

# Functions

Format returns a string describing how long it has been sincethe time argument passed int.