Time parsing of unusual timestamp format with milliseconds

I have the following timestamps, that i want to parse:

2022.05.14-00.37.13:544

I tried it with the following code snippet, but i could not parse the milliseconds:

package main

import (
	"fmt"
	"time"
)

func main() {
	s := "2022.05.14-00.37.13:544"
	t, err := time.Parse("2006.01.02-15.04.05:000", s)

	fmt.Println(t)
	fmt.Println(err)
}

It fails with:

parsing time "2022.05.14-00.37.13:544" as "2006.01.02-15.04.05:000": cannot parse "544" as ":000"

I tried different things, but none of them worked.
It only works if i remove the milliseconds.
What is the proper “reference string” to get this working also with the milliseconds?
Thanks for all hints.

Here is the Go Playground with the above code snippet:

I assume my above use case is currently not possible with the Go time parser, if i read this issue:

A workaround is to replace the colon with a period and then parse using layout “2006.01.02-15.04.05.000”

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