golang time.Format(time.UnixDate) return different value in different golang versions

Viewed 80

time.Format(time.UnixDate) is different in different environment

In windows, golang version: go version go1.16.4 windows/amd64

time.Format(time.UnixDate): Sat Jan 30 23:00:00 +0000 2021

While in WSL, golang verison: go version go1.15.13 linux/amd64

time.Format(time.UnixDate): Sat Jan 30 23:00:00 UTC 2021

I think "Sat Jan 30 23:00:00 UTC 2021" is the right one. But why "Sat Jan 30 23:00:00 +0000 2021" can be generated?

My test code:

package main

import (
    "fmt"
    "time"
)


func main() {
    now := time.Now() 
    fmt.Println("now UnixDate: " + now.Format(time.UnixDate))
    
    expireTime, err := time.Parse(time.RFC3339, "2021-01-30T23:00:00+00:00")
    if err != nil {
        fmt.Println(err)
    }
    fmt.Println("time.RFC3339: " + time.RFC3339)
    fmt.Println(expireTime)
    text, _ := expireTime.MarshalText()
    fmt.Println("MarshalText: " + string(text))
    fmt.Println("expireTime.Format: " + expireTime.Format(time.UnixDate))
    fmt.Println("time.UnixDate: " + time.UnixDate)
}

In windows, golang version: go version go1.16.4 windows/amd64

its output:

now UnixDate: Fri Jun 25 15:46:43 CST 2021
time.RFC3339: 2006-01-02T15:04:05Z07:00
2021-01-30 23:00:00 +0000 +0000
MarshalText: 2021-01-30T23:00:00Z
expireTime.Format: Sat Jan 30 23:00:00 +0000 2021
time.UnixDate: Mon Jan _2 15:04:05 MST 2006

while in WSL, golang verison: go version go1.15.13 linux/amd64

now UnixDate: Fri Jun 25 08:25:20 UTC 2021
time.RFC3339: 2006-01-02T15:04:05Z07:00
2021-01-30 23:00:00 +0000 UTC
MarshalText: 2021-01-30T23:00:00Z
expireTime.Format: Sat Jan 30 23:00:00 UTC 2021
time.UnixDate: Mon Jan _2 15:04:05 MST 2006
0 Answers
Related