Skip to content
This repository has been archived by the owner on Sep 8, 2023. It is now read-only.
/ ctimefmt Public archive
forked from Mottl/ctimefmt

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

observIQ/ctimefmt

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 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/observiq/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.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%