From: Pantelis Sampaziotis Date: Tue, 17 Sep 2019 19:01:36 +0000 (+0000) Subject: time: add examples for microseconds and milliseconds methods X-Git-Tag: go1.14beta1~1071 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=575386d6324308d83f6f0782e61620ffe9f5dba3;p=gostls13.git time: add examples for microseconds and milliseconds methods This change adds testable examples for the new Microseconds and Milliseconds methods that were introduced in Go 1.13. Fixes #34354 Change-Id: Ibdbfd770ca2192f9086f756918325f7327ce0482 GitHub-Last-Rev: 4575f48f5feb8e49742304d17776e28302647931 GitHub-Pull-Request: golang/go#34355 Reviewed-on: https://go-review.googlesource.com/c/go/+/195979 Reviewed-by: Alexander Rakoczy Reviewed-by: Ian Lance Taylor Run-TryBot: Alexander Rakoczy TryBot-Result: Gobot Gobot --- diff --git a/src/time/example_test.go b/src/time/example_test.go index 25c34ebc1c..4d70471a7d 100644 --- a/src/time/example_test.go +++ b/src/time/example_test.go @@ -113,6 +113,20 @@ func ExampleDuration_Hours() { // Output: I've got 4.5 hours of work left. } +func ExampleDuration_Microseconds() { + u, _ := time.ParseDuration("1s") + fmt.Printf("One second is %d microseconds.\n", u.Microseconds()) + // Output: + // One second is 1000000 microseconds. +} + +func ExampleDuration_Milliseconds() { + u, _ := time.ParseDuration("1s") + fmt.Printf("One second is %d milliseconds.\n", u.Milliseconds()) + // Output: + // One second is 1000 milliseconds. +} + func ExampleDuration_Minutes() { m, _ := time.ParseDuration("1h30m") fmt.Printf("The movie is %.0f minutes long.", m.Minutes())