strftime: Index | Examples | Files

package strftime

import ""

Package strftime provides a C99-compatible strftime formatter for use with Go time.Time instances.



Package Files


func Format Uses

func Format(t *time.Time, f string) string

Format accepts a Time pointer and a C99-compatible strftime format string and returns the formatted result. If the Time pointer is nil, the current time is used.

See for available conversion specifiers. Specific locale specifiers are not yet supported.


t := time.Date(2018, time.July, 9, 13, 14, 15, 0, time.UTC)

fmt.Println(Format(&t, "%c"))
fmt.Println(Format(&t, "%%Y-%%m-%%d -> %Y-%m-%d"))
fmt.Println(Format(&t, "%A is day number %w of the week."))
fmt.Println(Format(&t, "Last century was%n the %Cth century."))
fmt.Println(Format(&t, "Time zone: %Z"))


Mon Jul  9 13:14:15 2018
%Y-%m-%d -> 2018-07-09
Monday is day number 1 of the week.
Last century was
 the 20th century.
Time zone: UTC

Package strftime imports 6 packages (graph). Updated 2018-02-22. Refresh now. Tools for package owners.