Documentation
¶
Overview ¶
Package strftime implements C-like strftime functionality with locale support.
Package strftime implements C-like strftime functionality.
Package strftime provides locale-aware time formatting.
Package strftime implements C-like strftime functionality with locale support.
Package strftime implements C-like strftime functionality with locale support.
Package strftime implements C-like strftime functionality with locale support.
Package strftime implements C-like strftime format functionality with multiple locale support. It provides formatting of time.Time instances into strings using format specifiers similar to those used in C's strftime function. Supports various locales including English, Japanese, Chinese, and many European languages.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var EnglishFormatter = &Formatter{englishLocale}
EnglishFormatter is a pre-initialized English locale formatter. It can be used directly without calling New() for English locale formatting.
Functions ¶
func EnFormat ¶
EnFormat formats time t using format f with English locale. This is a convenience function that uses the pre-initialized EnglishFormatter.
Parameters:
- f: Format string with strftime-compatible format specifiers
- t: Time value to format
Returns: Formatted time string in English locale
func EnFormatF ¶
EnFormatF formats time t using format f in English locale and outputs it to the provided io.Writer. This is a more efficient alternative to EnFormat when the output is to be written directly.
Parameters:
- o: io.Writer to write the formatted output to
- f: Format string with strftime-compatible format specifiers
- t: Time value to format
Returns: Error if writing to the io.Writer fails
func Format ¶
Format is a shortcut to format a date in a given locale easily. Best performance is achieved by using language constants such as language.AmericanEnglish or language.French.
Parameters:
- l: Language tag to determine the locale for formatting
- f: Format string with strftime-compatible format specifiers
- t: Time value to format
Returns: Formatted time string according to the specified locale and format
Types ¶
type Formatter ¶
type Formatter struct {
// contains filtered or unexported fields
}
Formatter represents a time formatter with specific locale settings. It handles the formatting of time values according to the specified locale.
func New ¶
New creates a new Formatter by matching given language tags against known tags. If multiple language tags are provided, the best matching locale will be selected.
One sample use is as follows:
t, q, err := language.ParseAcceptLanguage(r.Header.Get("Accept-Language")) f := strftime.New(t...)
Parameters:
- l: One or more language tags to match against known locales
Returns: A new Formatter instance configured for the best matching locale
func (*Formatter) AppendFormat ¶
AppendFormat is like Format but appends the textual representation to b and returns the extended buffer. This is more efficient when building strings as it avoids unnecessary allocations.
Parameters:
- b: Byte slice to append the formatted time to
- f: Format string with strftime-compatible format specifiers
- t: Time value to format
Returns: The extended byte slice containing the original content followed by the formatted time
func (*Formatter) Format ¶
Format formats time using provided format, and returns a string. Uses the locale associated with this Formatter.
Parameters:
- f: Format string with strftime-compatible format specifiers
- t: Time value to format
Returns: Formatted time string according to this Formatter's locale
func (*Formatter) FormatF ¶
FormatF formats time using provided format, and outputs it to the provided io.Writer. This is more efficient than Format when the output is to be written directly.
Parameters:
- o: io.Writer to write the formatted output to
- f: Format string with strftime-compatible format specifiers
- t: Time value to format
Returns: Error if writing to the io.Writer fails