ezpz
commit
10fdf344d1
|
|
@ -0,0 +1,7 @@
|
|||
module strtime
|
||||
|
||||
go 1.21.0
|
||||
|
||||
require github.com/lestrrat-go/strftime v1.0.6
|
||||
|
||||
require github.com/pkg/errors v0.9.1 // indirect
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc h1:RKf14vYWi2ttpEmkA4aQ3j4u9dStX2t4M8UM6qqNsG8=
|
||||
github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc/go.mod h1:kopuH9ugFRkIXf3YoqHKyrJ9YfUFsckUU9S7B+XP+is=
|
||||
github.com/lestrrat-go/strftime v1.0.6 h1:CFGsDEt1pOpFNU+TJB0nhz9jl+K0hZSLE205AhTIGQQ=
|
||||
github.com/lestrrat-go/strftime v1.0.6/go.mod h1:f7jQKgV5nnJpYgdEasS+/y7EsTb8ykN2z68n3TtcTaw=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/lestrrat-go/strftime"
|
||||
)
|
||||
|
||||
func main() {
|
||||
in := flag.String("in", "2006-01-02T15:04:05", "input layout")
|
||||
out := flag.String("out", "%s", "output layout (or strftime)")
|
||||
flag.Parse()
|
||||
|
||||
formatter := func(t time.Time) string {
|
||||
return t.Format(*out)
|
||||
}
|
||||
if pattern, err := strftime.New(
|
||||
*out,
|
||||
strftime.WithUnixSeconds('s'),
|
||||
strftime.WithMilliseconds('L'),
|
||||
); err == nil {
|
||||
formatter = func(t time.Time) string {
|
||||
return pattern.FormatString(t)
|
||||
}
|
||||
}
|
||||
for _, flag := range flag.Args() {
|
||||
t, err := time.ParseInLocation(*in, flag, time.Local)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(formatter(t))
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue