Example: Directives: Note that %c returns RFC1123 which is a bit different from what Python does

go get



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.


Get the code down using the standard go tool:

go get

and write your code like

import ""

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.


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