Giter Club home page Giter Club logo

timefmt-go's Introduction

timefmt-go

CI Status Go Report Card MIT License release pkg.go.dev

Efficient time formatting library (strftime, strptime) for Golang

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.

Comparison to other libraries

  • This library
    • provides both formatting and parsing functions in pure Go language,
    • depends only on the Go standard libraries not to grow up dependency.
  • Format (strftime) implements glibc extensions including
    • width specifier like %6Y %10B %4Z (limited to 1024 bytes),
    • omitting padding modifier like %-y-%-m-%-d,
    • space padding modifier like %_y-%_m-%_d,
    • upper case modifier like %^a %^b,
    • swapping case modifier like %#Z,
    • time zone offset modifier like %:z %::z %:::z,
    • and its performance is very good.
  • AppendFormat is provided for reducing allocations.
  • Parse (strptime) allows to parse
    • composed directives like %F %T,
    • century years like %C %y,
    • week names like %A %a (parsed results are discarded).
  • ParseInLocation is provided for configuring the default location.

Bug Tracker

Report bug at Issues・itchyny/timefmt-go - GitHub.

Author

itchyny (https://github.com/itchyny)

License

This software is released under the MIT License, see LICENSE.

timefmt-go's People

Contributors

itchyny avatar yoh2 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.