0

I'm working with an external API that will sometimes shorten the returned timestamp if the last values are zero.

layout := "2006-01-02T15:04:05.000"
opened, err := time.Parse(layout, externallyFormattedTimestamp)
if err != nil {
    fmt.Println("something went wrong parsing the timestamp")
    fmt.Println(err.Error())
}

If the returned externallyFormattedTimestamp is 2018-11-05T06:19:59.827, this will parse without issue.

But if the time returned ends with zeros, it'll be shortened like 2018-11-05T06:19:59.8 instead of 2018-11-05T06:19:59.800, and break. Do I need to manually append zeros to the string before parsing, or is there something I missed built into Go that will handle this for me?

1 Answer 1

1

Use this layout instead: 2006-01-02T15:04:05.999

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.