I want to parse a date (having timezone) represented by a string into Time
.
I tried the below code:
package main
import (
"fmt"
"time"
)
func main() {
dateString := "Sat Jan 02 15:04:05 -0700 2021"
dateTime, _ := time.Parse("Mon Jan 02 15:04:05 -0700 2006", dateString)
zoneName, _ := dateTime.Zone()
fmt.Println("Zone Name is "+ zoneName)
loc, _ := time.LoadLocation(zoneName)
fmt.Println(loc)
}
On running the code I am getting the zoneName
as empty string which eventually transforms into UTC
whereas I should be getting a valid time zone? What mistake have I done to parse the date?
question from:
https://stackoverflow.com/questions/66063406/timezone-parsing-from-date-in-string-gives-empty-string 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…