File tree Expand file tree Collapse file tree 3 files changed +41
-0
lines changed
Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 2020| time\_ truncate\_ hours.go| time\_ truncate\_ hours| time.Timeから時刻部分を除去するサンプルです.|
2121| time\_ change\_ timezone.go| time\_ change\_ timezone| time.Timeをいろいろなタイム・ゾーンの値に変換するサンプルです|
2222| time\_ format\_ datetime.go| time\_ format\_ datetime| Go1.20で追加された time.DateTime フォーマット書式についてのサンプルです|
23+ | time\_ format\_ dateonly.go| time\_ format\_ dateonly| Go1.20で追加された time.DateOnly フォーマット書式についてのサンプルです|
Original file line number Diff line number Diff line change @@ -30,4 +30,5 @@ func (r *register) Regist(m mapping.ExampleMapping) {
3030 m ["time_in" ] = TimeIn
3131 m ["time_change_timezone" ] = ChangeTimeZone
3232 m ["time_format_datetime" ] = FormatDateTime
33+ m ["time_format_dateonly" ] = FormatDateOnly
3334}
Original file line number Diff line number Diff line change 1+ package times
2+
3+ import (
4+ "time"
5+
6+ "github.com/devlights/gomy/output"
7+ )
8+
9+ // FormatDateOnly は、Go1.20で追加された time.DateOnly フォーマット書式についてのサンプルです.
10+ //
11+ // # REFERENCES
12+ // - https://pkg.go.dev/time@go1.20.2#pkg-constants
13+ func FormatDateOnly () error {
14+ //
15+ // Go1.20 から、time.DateOnly (yyyy-MM-dd) というフォーマットが追加された
16+ // これにより、少しだけフォーマットする際に楽になった
17+ //
18+ var (
19+ locJst * time.Location
20+ now time.Time
21+ jst time.Time
22+ err error
23+ )
24+
25+ locJst , err = time .LoadLocation ("Asia/Tokyo" )
26+ if err != nil {
27+ return err
28+ }
29+
30+ now = time .Now ()
31+ jst = now .In (locJst )
32+
33+ output .Stdoutf ("[UTC ]" , "%v\n " , now .UTC ())
34+ output .Stdoutf ("[JST ]" , "%v\n " , jst )
35+ output .Stdoutf ("[time.DateOnly]" , "%s\n " , time .DateOnly )
36+ output .Stdoutf ("[time.Format ]" , "%s\n " , jst .Format (time .DateOnly ))
37+
38+ return nil
39+ }
You can’t perform that action at this time.
0 commit comments