go-strftime: github.com/imperfectgo/go-strftime Index | Examples | Files

package strftime

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

Index

Examples

Package Files

format.go stdtime_unsafe.go

func AppendFormat Uses

func AppendFormat(b []byte, t time.Time, layout string) []byte

AppendFormat is like Format but appends the textual representation to b and returns the extended buffer.

func Format Uses

func Format(t time.Time, layout string) string

Format returns a textual representation of the time value formatted according to C99-compatible strftime layout.

List of accepted specifiers:

%a  abbreviated weekday name (Sun)
%A  full weekday name (Sunday)
%b  abbreviated month name (Sep)
%B  full month name (September)
%c  the same as time.ANSIC (%a %b %e %H:%M:%S %)
%C  (year / 100) as number. Single digits are preceded by zero (20)
%d  day of month as number. Single digits are preceded by zero (21)
%D  equivalent to %m/%d/%y (09/21/14)
%e  day of month as number. Single digits are preceded by a blank (21)
%f  microsecond as a six digit decimal number, zero-padded on the left (001234)
%F  equivalent to %Y-%m-%d (2014-09-21)
%g  last two digits of ISO 8601 week-based year
%G  ISO 8601 week-based year
%h  same as %b
%H  the hour (24 hour clock) as a number. Single digits are preceded by zero (15)
%I  the hour (12 hour clock) as a number. Single digits are preceded by zero (03)
%j  the day of the year as a decimal number. Single digits are preced by zeros (264)
%m  the month as a decimal number. Single digits are preceded by a zero (09)
%M  the minute as a decimal number. Single digits are preceded by a zero (32)
%n  a newline (\n)
%p  AM or PM as appropriate
%P  am or pm as appropriate
%r  equivalent to %I:%M:%S %p
%R  equivalent to %H:%M
%S  the second as a number. Single digits are preceded by a zero (05)
%t  a tab (\t)
%T  equivalent to %H:%M:%S
%u  weekday as a decimal number, where Monday is 1
%U  week of the year as a decimal number (Sunday is the first day of the week)
%V  ISO 8601 week of the year
%w  the weekday (Sunday as first day of the week) as a number. (0)
%W  week of the year as a decimal number (Monday is the first day of the week)
%x  equivalent to %m/%d/%Y
%X  equivalent to %H:%M:%S
%y  year without century as a number. Single digits are preceded by zero (14)
%Y  the year with century as a number (2014)
%z  the time zone offset from UTC (-0700)
%Z  time zone name (UTC)

Code:

t := time.Date(2008, 9, 3, 20, 4, 26, 654321000, time.FixedZone("CST", 8*3600))

fmt.Println(Format(t, "%c"))
fmt.Println(Format(t, "%Y-%m-%dT%H:%M:%S.%f%z"))
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"))

Output:

Wed Sep  3 20:04:26 2008
2008-09-03T20:04:26.654321+0800
Wednesday is day number 3 of the week.
Last century was
 the 20th century.
Time zone: CST

Package strftime imports 2 packages (graph). Updated 2018-09-26. Refresh now. Tools for package owners.