Skip to content

hhkbp2/go-strftime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-strftime

go-strftime is a Golang library that implements the Python-like Time Format Function strftime().

According to this discussion Issue 444: Implement strftime, in the eyes of the Golang designer, the strftime() is a bad interface and should be replaced by time.Format() because the later one has a simpler format representation. However the formats could be used in time.Format() is strictly limited to a few pre-defined constants. Sometimes it would become error-prone and tricky to use the format right to produce what format programmers want exactly other than the pre-defineds.

So this library is created to provide a convenient interface for those who like to use strftime() in Golang.

Usage

Get the code down using the standard go tool:

go get github.com/hhkbp2/go-strftime

and write your code like

import "github.com/hhkbp2/go-strftime"

formatted := stftime.Format("%Y-%m-%d %H:%M:%S %9n", time.Now())

Please refer to the Python strftime doc for all the supported format strings. Note that there are two differences:

  1. %c returns RFC1123 which is a bit different from what Python does
  2. %[1-9]n is added for fractional second. e.g. "%3n" means to print millisecond offset with this second. "%6n" means to print microsecond. "%9n" is for nanosecond.

Contributors

This library is originally developed by Miki Tebeka and forked by Dylan Wen to add fractional format support.

The original repository could be found at https://bitbucket.org/tebeka/strftime.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages