Skip to content

Latest commit

 

History

History
42 lines (33 loc) · 1012 Bytes

README.md

File metadata and controls

42 lines (33 loc) · 1012 Bytes

ctimefmt

GoDoc

strptime/strftime compatible syntax (e.g. "%Y-%m-%d %H:%M:%S %Z") for Go.

Installation

go get github.com/Mottl/ctimefmt

Example

package main

import (
    "fmt"
    "time"
    "github.com/Mottl/ctimefmt"
)

func main() {
    now := time.Now()
    // Format() function formats Time struct:
    fmt.Println(ctimefmt.Format("%Y-%m-%d %H:%M:%S.%f %Z", now))

    // ToNative() converts ctime-like format string to Go native layout:
    s := ctimefmt.ToNative("%Y-%m-%d %H:%M:%S.%f %Z")
    fmt.Println(now.Format(s)))

    // Parse() parses ctime-like syntax to Time struct:
    if then, err := ctimefmt.Parse("%Y-%m-%d %H:%M:%S", "2019-02-19 17:25:05"); err == nil {
        fmt.Println(then)
    } else {
        fmt.Println("Error parsing time:", err)
    }
}

License

Use of this package is governed by MIT license that can be found in the LICENSE file.