File tree Expand file tree Collapse file tree 4 files changed +42
-1
lines changed
Expand file tree Collapse file tree 4 files changed +42
-1
lines changed Original file line number Diff line number Diff line change 2121| time\_ change\_ timezone.go| time\_ change\_ timezone| time.Timeをいろいろなタイム・ゾーンの値に変換するサンプルです|
2222| time\_ format\_ datetime.go| time\_ format\_ datetime| Go1.20で追加された time.DateTime フォーマット書式についてのサンプルです|
2323| time\_ format\_ dateonly.go| time\_ format\_ dateonly| Go1.20で追加された time.DateOnly フォーマット書式についてのサンプルです|
24+ | time\_ format\_ timeonly.go| time\_ format\_ timeonly| Go1.20で追加された time.TimeOnly フォーマット書式についてのサンプルです|
Original file line number Diff line number Diff line change @@ -31,4 +31,5 @@ func (r *register) Regist(m mapping.ExampleMapping) {
3131 m ["time_change_timezone" ] = ChangeTimeZone
3232 m ["time_format_datetime" ] = FormatDateTime
3333 m ["time_format_dateonly" ] = FormatDateOnly
34+ m ["time_format_timeonly" ] = FormatTimeOnly
3435}
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ func FormatDateTime() error {
3232
3333 output .Stdoutf ("[UTC ]" , "%v\n " , now .UTC ())
3434 output .Stdoutf ("[JST ]" , "%v\n " , jst )
35- output .Stdoutf ("[time.DateTime ]" , "%s\n " , time .DateTime )
35+ output .Stdoutf ("[time.DateOnly ]" , "%s\n " , time .DateTime )
3636 output .Stdoutf ("[time.Format ]" , "%s\n " , jst .Format (time .DateTime ))
3737
3838 return nil
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+ // FormatDateTime は、Go1.20で追加された time.TimeOnly フォーマット書式についてのサンプルです.
10+ //
11+ // # REFERENCES
12+ // - https://pkg.go.dev/time@go1.20.2#pkg-constants
13+ func FormatTimeOnly () error {
14+ //
15+ // Go1.20 から、time.DateTime (yyyy-MM-dd HH:mm:ss) というフォーマットが追加された
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.TimeOnly]" , "%s\n " , time .TimeOnly )
36+ output .Stdoutf ("[time.Format ]" , "%s\n " , jst .Format (time .TimeOnly ))
37+
38+ return nil
39+ }
You can’t perform that action at this time.
0 commit comments