Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/itchyny/timefmt-go
Efficient time formatting library (strftime, strptime) for Golang
https://github.com/itchyny/timefmt-go
Last synced: about 1 month ago
JSON representation
Efficient time formatting library (strftime, strptime) for Golang
- Host: GitHub
- URL: https://github.com/itchyny/timefmt-go
- Owner: itchyny
- License: mit
- Created: 2020-07-23T20:32:09.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-06-01T14:24:03.000Z (4 months ago)
- Last Synced: 2024-06-18T13:58:01.487Z (3 months ago)
- Language: Go
- Homepage:
- Size: 106 KB
- Stars: 173
- Watchers: 4
- Forks: 15
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# timefmt-go
[![CI Status](https://github.com/itchyny/timefmt-go/actions/workflows/ci.yaml/badge.svg?branch=main)](https://github.com/itchyny/timefmt-go/actions?query=branch:main)
[![Go Report Card](https://goreportcard.com/badge/github.com/itchyny/timefmt-go)](https://goreportcard.com/report/github.com/itchyny/timefmt-go)
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/itchyny/timefmt-go/blob/main/LICENSE)
[![release](https://img.shields.io/github/release/itchyny/timefmt-go/all.svg)](https://github.com/itchyny/timefmt-go/releases)
[![pkg.go.dev](https://pkg.go.dev/badge/github.com/itchyny/timefmt-go)](https://pkg.go.dev/github.com/itchyny/timefmt-go)### Efficient time formatting library (strftime, strptime) for Golang
This is a Go language package for formatting and parsing date time strings.```go
package mainimport (
"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 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 to [`man 3 strftime`](https://linux.die.net/man/3/strftime) and
[`man 3 strptime`](https://linux.die.net/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 default location.![](https://user-images.githubusercontent.com/375258/88606920-de475c80-d0b8-11ea-8d40-cbfee9e35c2e.jpg)
## Bug Tracker
Report bug at [Issues・itchyny/timefmt-go - GitHub](https://github.com/itchyny/timefmt-go/issues).## Author
itchyny ()## License
This software is released under the MIT License, see LICENSE.