Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

timefmt-go

> 编程语言
Open source

Efficient time formatting library (strftime, strptime) for Golang

194 stars0 likes0 views
WebsiteGitHub

About

Efficient time formatting library (strftime, strptime) for Golang

timefmt-go

Efficient time formatting library (strftime, strptime) for Go

This is a Go language package for formatting and parsing date time strings.

go
package main

import (
	"fmt"
	"log"

	"github.com/itchyny/timefmt-go"
)

func main() {
	t, err := timefmt.Parse("2020/07/24 09:07:29", "%Y/%m/%d %H:%M:%S")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(t) // 2020-07-24 09:07:29 +0000 UTC

	str := timefmt.Format(t, "%Y/%m/%d %H:%M:%S")
	fmt.Println(str) // 2020/07/24 09:07:29

	str = timefmt.Format(t, "%a, %d %b %Y %T %z")
	fmt.Println(str) // Fri, 24 Jul 2020 09:07:29 +0000
}

Please refer to man 3 strftime and man 3 strptime for formatters. As an extension, %f directive is supported for zero-padded microseconds, which originates from Python. Note that E and O modifier characters are not supported.

Comparison to other libraries

  • This library
    • provides both formatting and parsing functions in pure Go language,
    • depends only on the Go standard libraries not to grow up dependency.
  • Format (strftime) implements glibc extensions including
    • width specifier like %6Y %10B %4Z (limited to 1024 bytes),
    • omitting padding modifier like %-y-%-m-%-d,
    • space padding modifier like %_y-%_m-%_d,
    • upper case modifier like %^a %^b,
    • swapping case modifier like %#Z,
    • time zone offset modifier like %:z %::z %:::z,
    • and its performance is very good.
  • AppendFormat is provided for reducing allocations.
  • Parse (strptime) allows to parse
    • composed directives like %F %T,
    • century years like %C %y,
    • week directives like %W %a and %G-W%V-%u.
  • ParseInLocation is provided for configuring the location of a source without a time zone offset.

Bug Tracker

Report bugs at Issues - itchyny/timefmt-go - GitHub.

Author

itchyny ()

License

This software is released under the MIT License, see LICENSE.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Go

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言