diff options
Diffstat (limited to 'docs/content/en/functions/time/Format.md')
-rw-r--r-- | docs/content/en/functions/time/Format.md | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/docs/content/en/functions/time/Format.md b/docs/content/en/functions/time/Format.md index 3a0b1eb2a..74384959b 100644 --- a/docs/content/en/functions/time/Format.md +++ b/docs/content/en/functions/time/Format.md @@ -1,51 +1,52 @@ --- title: time.Format -description: Returns a formatted and localized time.Time value. -categories: [functions] +description: Returns the given date/time as a formatted and localized string. +categories: [] keywords: [] -menu: - docs: - parent: functions -function: +action: aliases: [dateFormat] + related: + - functions/time/AsTime + - functions/time/Duration + - functions/time/Now + - functions/time/ParseDuration returnType: string signatures: [time.Format LAYOUT INPUT] -relatedFunctions: - - time.AsTime - - time.Duration - - time.Format - - time.Now - - time.ParseDuration aliases: [/functions/dateformat] toc: true --- -```go-template -{{ $t := "2023-01-27T23:44:58-08:00" }} -{{ $format := "2 Jan 2006" }} +Use the `time.Format` function with `time.Time` values: -{{ $t | time.Format $format }} → 27 Jan 2023 +```go-html-template +{{ $t := time.AsTime "2023-02-27T23:44:58-08:00" }} +{{ time.Format "2 Jan 2006" $t }} → 27 Feb 2023 +``` + +Or use `time.Format` with a *parsable* string representation of a date/time value: -{{ $t = time.AsTime $t }} -{{ $t | time.Format $format }} → 27 Jan 2023 +```go-html-template +{{ $t := "27 Feb 2023" }} +{{ time.Format "January 2, 2006" $t }} → February 27, 2023 ``` +Examples of parsable string representations: + +{{% include "functions/time/_common/parsable-date-time-strings.md" %}} + ## Layout string -{{% readfile file="/functions/_common/time-layout-string.md" %}} +{{% include "functions/_common/time-layout-string.md" %}} ## Localization Use the `time.Format` function to localize `time.Time` values for the current language and region. -{{% note %}} -{{% readfile file="/functions/_common/locales.md" %}} -{{% /note %}} - +{{% include "functions/_common/locales.md" %}} Use the layout string as described above, or one of the tokens below. For example: -```go-template +```go-html-template {{ .Date | time.Format ":date_medium" }} → Jan 27, 2023 ``` |