strftime

package module
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2020 License: MIT Imports: 3 Imported by: 1

README

strftime for Go

Test go.dev reference

Q: Why? We already have time.Format.

A: Yes, but it becomes tricky to use if if you have string with things other than time in them. (like /path/to/%Y/%m/%d/report)

Installing

go get github.com/tebeka/strftime

Example

str, err := strftime.Format("%Y/%m/%d", time.Now())

Contact

https://github.com/tebeka/strftime

Documentation

Overview

Package strftime implements Python's strftime in Go

Example:

str, err := strftime.Format("%Y/%m/%d", time.Now()) // 2019/07/07

Directives:

%a - Locale’s abbreviated weekday name
%A - Locale’s full weekday name
%b - Locale’s abbreviated month name
%B - Locale’s full month name
%c - Locale’s appropriate date and time representation
%d - Day of the month as a decimal number [01,31]
%H - Hour (24-hour clock) as a decimal number [00,23]
%I - Hour (12-hour clock) as a decimal number [01,12]
%j - Day of year
%m - Month as a decimal number [01,12]
%M - Minute as a decimal number [00,59]
%p - Locale’s equivalent of either AM or PM
%S - Second as a decimal number [00,61]
%U - Week number of the year
%w - Weekday as a decimal number
%W - Week number of the year
%x - Locale’s appropriate date representation
%X - Locale’s appropriate time representation
%y - Year without century as a decimal number [00,99]
%Y - Year with century as a decimal number
%Z - Time zone name (no characters if no time zone exists)

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

Index

Constants

View Source
const (
	// Version is the package version
	Version = "0.1.5"

	// Week in time.Duration
	Week = time.Hour * 24 * 7
)

Variables

This section is empty.

Functions

func Format

func Format(format string, t time.Time) (string, error)

Format return string with % directives expanded. Will return error on unknown directive.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL