Add中week增加类型转换 (#554)

cannot use week (type float64) as type time.Duration in argument to t.Add
This commit is contained in:
Cooli7wa
2018-11-06 05:41:30 +08:00
committed by 无闻
parent cf7001dcd0
commit 3ed4f65f83

View File

@@ -40,7 +40,7 @@ func main() {
fmt.Println(time.Now()) // Wed Dec 21 09:52:14 +0100 RST 2011 fmt.Println(time.Now()) // Wed Dec 21 09:52:14 +0100 RST 2011
// calculating times: // calculating times:
week = 60 * 60 * 24 * 7 * 1e9 // must be in nanosec week = 60 * 60 * 24 * 7 * 1e9 // must be in nanosec
week_from_now := t.Add(week) week_from_now := t.Add(time.Duration(week))
fmt.Println(week_from_now) // Wed Dec 28 08:52:14 +0000 UTC 2011 fmt.Println(week_from_now) // Wed Dec 28 08:52:14 +0000 UTC 2011
// formatting times: // formatting times:
fmt.Println(t.Format(time.RFC822)) // 21 Dec 11 0852 UTC fmt.Println(t.Format(time.RFC822)) // 21 Dec 11 0852 UTC