Converting Date Formats in Go
Question:
How can I convert a date in the format "2010-01-23 11:44:20" to "Jan 23 '10 at 11:44" using Go?
Answer:
To convert between different date formats in Go, you can utilize the Parse and Format functions from the time package. Both functions accept a reference time (in the desired format) as a parameter, simplifying the formatting process.
Example:
dtstr1 := "2010-01-23 11:44:20" dt, _ := time.Parse("2006-01-02 15:04:05", dtstr1) dtstr2 := dt.Format("Jan 2 '06 at 15:04")
This code will convert the original date string to the desired "Jan 23 '10 at 11:44" format using the following steps:
The above is the detailed content of How to Convert 'YYYY-MM-DD HH:mm:ss' to 'Mon DD 'YY at HH:mm' in Go?. For more information, please follow other related articles on the PHP Chinese website!