Time Equal Handles Zones And Monotonic
Compare times with Equal and Compare: the eq operator fails across locations and after Round strips the monotonic clock reading.
Code
package main
import (
"fmt"
"time"
)
func main() {
utc := time.Date(2026, 11, 21, 9, 0, 0, 0, time.UTC)
est := time.FixedZone("EST", -5*3600) // 固定时区 zone,无需时区数据库
sameInstant := utc.In(est) // 同一时间点,不同时区表示
// == 逐字段比较:位置不同即判不等
fmt.Println("eq op:", utc == sameInstant)
// Equal 只比较时间点,忽略位置与单调时钟读数
fmt.Println("Equal:", utc.Equal(sameInstant))
now := time.Now()
stripped := now.Round(0) // Round(0) 剥离单调时钟读数 monotonic clock reading
fmt.Println("now == stripped:", now == stripped)
fmt.Println("now Equal stripped:", now.Equal(stripped))
// Compare 返回三态顺序,同样只看时间点本身
fmt.Println("Compare:", now.Compare(stripped))
}Inside the code
Under the hood: the function main.
Points of care
- The API surface is all built-in — no supply chain to review.
Using it
The main signature reads func main()
The output comes labeled — eq op:, Equal:, now == stripped: — when the file runs.
Key statements
stripped := now.Round(0) // Round(0) 剥离单调时钟读数 monotonic clock reading
Interactive Tools for This Topic
cURL to Python & Go ConverterTranslate curl CLI commands with headers, auth, JSON bodies, and timeouts into ready-to-run Python requests and Go net/http client code snippets.Duration ConverterConvert between human durations like 1w2d3h45m and total seconds, hours, and minutes with negative support.Duration HumanizerTurn a number of seconds into a readable duration such as 1 day, 2 hours, 3 minutes, and show the equivalent in minutes and hours.ISO 8601 Duration ParserParse ISO 8601 durations like PT1H30M into year, month, week, day, and time components with exact or approximate total seconds.
FAQ
- What does Time Equal Handles Zones And Monotonic print when run?
- Running the file directly is enough — expect labeled output lines such as `eq op:`, `Equal:`, `now == stripped:`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.