Golang default time format does not have a constant defined

Hello All,

I am trying using time.Parse() to convert a time in string format back to the golang time format.

The time string is in the default golang format
"2006-01-02 15:04:05.999999999 -0700 MST"

I have to manually define the layout when calling time.Parse() because there is no constant predefined within the time library.

For example…
const longFormat = "2006-01-02 15:04:05.999999999 -0700 MST"
createTimeStamp, err := time.Parse(longFormat, timeStringIWishToParse)

Is there any plan to create this format as a constant? Otherwise, we will have to devise a pattern to define this format globally. I’d like to avoid doing this.

Here is what the documentation defines so far…

Many Thanks!

To see if there’s a plan to change this, look for open issues at https://github.com/golang/go/issues - if there is none, assume there is no plan.

I can agree that this looks like an odd oversight.

That said, if you’re producing the data yourself you can lock down the format yourself. You can probably also assume that the default Go format string isn’t going to change.

Looks like they don’t want you to use the default format.

Either RYO or use the existing constants. Strange, but at least I can make decision now.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.