GO語言"time"包中"Time.Add"類型的用法及代碼示例。
用法:
func(t Time) Add(d Duration) Time
Add 返回時間 t+d。
例子:
package main
import (
"fmt"
"time"
)
func main() {
start := time.Date(2009, 1, 1, 12, 0, 0, 0, time.UTC)
afterTenSeconds := start.Add(time.Second * 10)
afterTenMinutes := start.Add(time.Minute * 10)
afterTenHours := start.Add(time.Hour * 10)
afterTenDays := start.Add(time.Hour * 24 * 10)
fmt.Printf("start = %v\n", start)
fmt.Printf("start.Add(time.Second * 10) = %v\n", afterTenSeconds)
fmt.Printf("start.Add(time.Minute * 10) = %v\n", afterTenMinutes)
fmt.Printf("start.Add(time.Hour * 10) = %v\n", afterTenHours)
fmt.Printf("start.Add(time.Hour * 24 * 10) = %v\n", afterTenDays)
}
輸出:
start = 2009-01-01 12:00:00 +0000 UTC start.Add(time.Second * 10) = 2009-01-01 12:00:10 +0000 UTC start.Add(time.Minute * 10) = 2009-01-01 12:10:00 +0000 UTC start.Add(time.Hour * 10) = 2009-01-01 22:00:00 +0000 UTC start.Add(time.Hour * 24 * 10) = 2009-01-11 12:00:00 +0000 UTC
相關用法
- GO Time.AddDate用法及代碼示例
- GO Time.After用法及代碼示例
- GO Time.AppendFormat用法及代碼示例
- GO Time.Sub用法及代碼示例
- GO Time.Equal用法及代碼示例
- GO Time.Format用法及代碼示例
- GO Time.Truncate用法及代碼示例
- GO Time.Date用法及代碼示例
- GO Time.Round用法及代碼示例
- GO Time.GoString用法及代碼示例
- GO Time.Day用法及代碼示例
- GO Time.String用法及代碼示例
- GO Time.Unix用法及代碼示例
- GO Time.Before用法及代碼示例
- GO Title用法及代碼示例
- GO Tick用法及代碼示例
- GO TrailingZeros8用法及代碼示例
- GO Tx.ExecContext用法及代碼示例
- GO Template用法及代碼示例
- GO ToTitle用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 Time.Add。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。