This is a Go language package for formatting and parsing date time strings.
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.
Format
(strftime
) implements glibc extensions including
%6Y %10B %4Z
(limited to 1024 bytes),%-y-%-m-%-d
,%_y-%_m-%_d
,%^a %^b
,%#Z
,%:z %::z %:::z
,AppendFormat
is provided for reducing allocations.Parse
(strptime
) allows to parse
%F %T
,%C %y
,%W %a
and %G-W%V-%u
.ParseInLocation
is provided for configuring the default location.Report bug at Issues・itchyny/timefmt-go - GitHub.
itchyny (https://github.com/itchyny)
This software is released under the MIT License, see LICENSE.