Since Unix time does not take leap seconds into account, and standard UTC does, I would expect to see a difference of 27 seconds (the leap seconds since epoch) when I go back and forth in such code, but it give me back exactly the same date/time.
The time.Now() is synchronized with the official time, that is UTC.
There seems to be a thing I did not catch in the Go handling of time.
nn:=time.Now()
fmt.Println(nn)
fmt.Println(time.Now().UTC())
fmt.Println(nn.Unix())
rfc:=nn.Format(time.RFC3339)
fmt.Println(rfc)
thetime, e := time.Parse(time.RFC3339, rfc)
if e != nil {
panic(“Can’t parse time format”)
}
epoch := thetime.Unix()
fmt.Println(epoch)
Thank you for your answer. It “clarifies” where the problem is.
For those who are interested, here is an example showing the error.
func main() {
epoch:=time.Date(1970,1,1,0,0,0,0,time.UTC)
fmt.Printf(" epoch en date: %v\n",epoch)
uepoch:=int64(epoch.Unix())
fmt.Printf(" epoch en unix timestamp: %v\n",uepoch)
startprocess :=time.Date(2008,12,31,23,59,59,0,time.UTC)
fmt.Printf(“process start at: %v (correct time)\n”,startprocess)
ustartprocess :=startprocess.Unix()
fmt.Printf(“unix timestamp of starting process: %v\n”,ustartprocess)
intendingprocess:=ustartprocess+4
fmt.Printf(“process end timestamp: %v,\n”,intendingprocess)
endingdate:=time.Unix(intendingprocess,0)
fmt.Printf(“endingdate: %v\n”,endingdate)
Thank you, actually the confusion (for me) is deeper than that. If you look at the example in my other reply it shows there is a problem with mixing monotonic and wall clock, and this leads to errors. If I add the actual number of seconds to a process around the leap second, I find my 27 seconds.