SoFunction
Updated on 2025-03-04

Problems based on golang time conversion

Generally, when you get the time string and need to format the time string into the "" object of golang, there are usually two functions, namely.

(layout, value string) (Time, error)
(layout, value string, loc *Location) (Time, error)

The difference between the two functions is that when the Parse() function is parsed, it will be destructed to UTC time. After the obtained Time object is converted into a Unix() object, it will be 8 hours more than the current time.

tm, err := ("2006-01-02T15:04:05Z", s) //Time after conversion,If converted tounixtime,need-8Hour

If the parsing source is GMT time, it is best to use ParseInLocation() and specify "*Location" as "", for example:

tm, err = ("2006-01-02T15:04:05Z", s, ) //If the converted time is converted to unix time, it does not need to be processed.

The above question based on golang time conversion is all the content I share with you. I hope you can give you a reference and I hope you can support me more.