Skip to content
/ ctimefmt Public

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

License

Notifications You must be signed in to change notification settings

Mottl/ctimefmt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages