Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Efficient time formatting library (strftime, strptime) for Golang

License

NotificationsYou must be signed in to change notification settings

itchyny/timefmt-go

Repository files navigation

CI StatusGo Report CardMIT Licensereleasepkg.go.dev

Efficient time formatting library (strftime, strptime) for Golang

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

package mainimport ("fmt""log""github.com/itchyny/timefmt-go")funcmain() {t,err:=timefmt.Parse("2020/07/24 09:07:29","%Y/%m/%d %H:%M:%S")iferr!=nil {log.Fatal(err)}fmt.Println(t)// 2020-07-24 09:07:29 +0000 UTCstr:=timefmt.Format(t,"%Y/%m/%d %H:%M:%S")fmt.Println(str)// 2020/07/24 09:07:29str=timefmt.Format(t,"%a, %d %b %Y %T %z")fmt.Println(str)// Fri, 24 Jul 2020 09:07:29 +0000}

Please refer toman 3 strftime andman 3 strptime for formatters.As an extension,%f directive is supported for zero-padded microseconds, which originates from Python.Note thatE andO 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 default location.

Bug Tracker

Report bug atIssues・itchyny/timefmt-go - GitHub.

Author

itchyny (https://github.com/itchyny)

License

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

About

Efficient time formatting library (strftime, strptime) for Golang

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp