I'm trying to parse a string into a time object. The issue is that the number of digits in the microseconds term changes, which breaks the parsing. For example, this works fine:
package main
import (
"fmt"
"time"
)
func main() {
timeText := "2017-03-25T10:01:02.1234567Z"
layout := "2006-01-02T15:04:05.0000000Z"
t, _ := time.Parse(layout, timeText)
fmt.Println(t)
}
But this causes an error, because the number of microseconds digits doesn't match the layout:
package main
import (
"fmt"
"time"
)
func main() {
timeText := "2017-03-25T10:01:02.123Z" // notice only 3 microseconds digits here
layout := "2006-01-02T15:04:05.0000000Z"
t, _ := time.Parse(layout, timeText)
fmt.Println(t)
}
How do I fix this so that the microseconds term is still parsed, but it doesn't matter how many digits there are?