File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed
Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 2323| time_format_dateonly.go | time_format_dateonly | Go1.20で追加された time.DateOnly フォーマット書式についてのサンプルです |
2424| time_format_timeonly.go | time_format_timeonly | Go1.20で追加された time.TimeOnly フォーマット書式についてのサンプルです |
2525| time_format_millisecond.go | time_format_millisecond | time.Format() にてミリ秒を出力するサンプルです。 |
26+ | time_format_microsecond.go | time_format_microsecond | time.Format() にてマイクロ秒を出力するサンプルす。 |
2627| time_calc_nextmonth.go | time_calc_nextmonth | 翌月の日付を求めるサンプルです |
2728| time_daysinmonth.go | time_daysinmonth | 月の日数を求めるサンプルです |
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ func (r *register) Regist(m mapping.ExampleMapping) {
3333 m ["time_format_dateonly" ] = FormatDateOnly
3434 m ["time_format_timeonly" ] = FormatTimeOnly
3535 m ["time_format_millisecond" ] = FormatMillisecond
36+ m ["time_format_microsecond" ] = FormatMicrosecond
3637 m ["time_calc_nextmonth" ] = CalcNextMonth
3738 m ["time_daysinmonth" ] = DaysInMonth
3839}
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+ // FormatMicrosecond は、time.Format() にてマイクロ秒を出力するサンプルです。
10+ //
11+ // マイクロ秒をフォーマットするには ".000000" とする。
12+ // ドットを付けないとフォーマットされないので注意。
13+ //
14+ // # REFERENCES
15+ // - https://pkg.go.dev/time@go1.22.1#Time.Format
16+ func FormatMicrosecond () error {
17+ var (
18+ microsec = func () string { return time .Now ().Format ("05.000000" ) }
19+ wait100ms = func () { time .Sleep ((100 * 1000 ) * time .Microsecond ) }
20+ )
21+
22+ output .Stdoutl ("[1]" , microsec ())
23+ wait100ms ()
24+ output .Stdoutl ("[2]" , microsec ())
25+ wait100ms ()
26+ output .Stdoutl ("[3]" , microsec ())
27+
28+ for range 5 {
29+ wait100ms ()
30+ }
31+
32+ output .Stdoutl ("[4]" , microsec ())
33+
34+ return nil
35+
36+ /*
37+ $ task
38+ task: [build] go build .
39+ task: [run] ./try-golang -onetime
40+
41+ ENTER EXAMPLE NAME: time_format_microsecond
42+
43+ [Name] "time_format_microsecond"
44+ [1] 31.695992
45+ [2] 31.796184
46+ [3] 31.896460
47+ [4] 32.397545
48+
49+
50+ [Elapsed] 701.582286ms
51+ */
52+
53+ }
You can’t perform that action at this time.
0 commit comments