This question already has an answer here:
- Parsing date string in Go 6 answers
I have a string time in format 20171023T183552
. I didn't find any format to parse this string value. Is there any way to convert this string value to Go time.Time ?
Edit - This is not duplicate question. I know how to parse, but I was unaware of the fact that we can use any layout other than listed in time format package. This answer cleared my daubt.
That is simply
"YYYYMMDDTHHmmSS"
, so use the format string (layout):"20060102T150405"
.Example:
Output (try it on the Go Playground):
Quoting from doc of
time.Parse()
:So basically generate the format string by formatting the reference time using the same format your input is available in.
For the opposite direction (converting
time.Time
tostring
), see Golang: convert time.Time to string.