GO語言"time"包中"Time.Equal"類型的用法及代碼示例。
用法:
func(t Time) Equal(u Time) bool
Equal 報告 t 和 u 是否代表同一時刻。即使它們在不同的位置,兩次也可以相等。例如,6:00 +0200 和 4:00 UTC 是相等的。有關將 == 與 Time 值一起使用的陷阱,請參閱有關 Time 類型的文檔;大多數代碼應該使用 Equal 代替。
例子:
package main
import (
"fmt"
"time"
)
func main() {
secondsEastOfUTC := int((8 * time.Hour).Seconds())
beijing := time.FixedZone("Beijing Time", secondsEastOfUTC)
// Unlike the equal operator, Equal is aware that d1 and d2 are the
// same instant but in different time zones.
d1 := time.Date(2000, 2, 1, 12, 30, 0, 0, time.UTC)
d2 := time.Date(2000, 2, 1, 20, 30, 0, 0, beijing)
datesEqualUsingEqualOperator := d1 == d2
datesEqualUsingFunction := d1.Equal(d2)
fmt.Printf("datesEqualUsingEqualOperator = %v\n", datesEqualUsingEqualOperator)
fmt.Printf("datesEqualUsingFunction = %v\n", datesEqualUsingFunction)
}
輸出:
datesEqualUsingEqualOperator = false datesEqualUsingFunction = true
相關用法
- GO Time.Sub用法及代碼示例
- GO Time.After用法及代碼示例
- GO Time.Format用法及代碼示例
- GO Time.AppendFormat用法及代碼示例
- GO Time.AddDate用法及代碼示例
- GO Time.Truncate用法及代碼示例
- GO Time.Date用法及代碼示例
- GO Time.Round用法及代碼示例
- GO Time.Add用法及代碼示例
- 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.Equal。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。