| 1 |
--- |
| 2 |
_comment: Do not remove front matter. |
| 3 |
--- |
| 4 |
|
| 5 |
Format a `time.Time` value based on [Go's reference time][]: |
| 6 |
|
| 7 |
```text |
| 8 |
Mon Jan 2 15:04:05 MST 2006 |
| 9 |
``` |
| 10 |
|
| 11 |
Create a layout string using these components: |
| 12 |
|
| 13 |
Description|Valid components |
| 14 |
:--|:-- |
| 15 |
Year|`"2006" "06"` |
| 16 |
Month|`"Jan" "January" "01" "1"` |
| 17 |
Day of the week|`"Mon" "Monday"` |
| 18 |
Day of the month|`"2" "_2" "02"` |
| 19 |
Day of the year|`"__2" "002"` |
| 20 |
Hour|`"15" "3" "03"` |
| 21 |
Minute|`"4" "04"` |
| 22 |
Second|`"5" "05"` |
| 23 |
AM/PM mark|`"PM"` |
| 24 |
Time zone offsets|`"-0700" "-07:00" "-07" "-070000" "-07:00:00"` |
| 25 |
|
| 26 |
Replace the sign in the layout string with a Z to print Z instead of an offset for the UTC zone. |
| 27 |
|
| 28 |
Description|Valid components |
| 29 |
:--|:-- |
| 30 |
Time zone offsets|`"Z0700" "Z07:00" "Z07" "Z070000" "Z07:00:00"` |
| 31 |
|
| 32 |
```go-html-template |
| 33 |
{{ $t := "2023-01-27T23:44:58-08:00" }} |
| 34 |
{{ $t = time.AsTime $t }} |
| 35 |
{{ $t = $t.Format "Jan 02, 2006 3:04 PM Z07:00" }} |
| 36 |
|
| 37 |
{{ $t }} → Jan 27, 2023 11:44 PM -08:00 |
| 38 |
``` |
| 39 |
|
| 40 |
Strings such as `PST` and `CET` are not time zones. They are time zone _abbreviations_. |
| 41 |
|
| 42 |
Strings such as `-07:00` and `+01:00` are not time zones. They are time zone _offsets_. |
| 43 |
|
| 44 |
A time zone is a geographic area with the same local time. For example, the time zone abbreviated by `PST` and `PDT` (depending on Daylight Savings Time) is `America/Los_Angeles`. |
| 45 |
|
| 46 |
[Go's reference time]: https://pkg.go.dev/time#pkg-constants |