I am taking a user input, "2023-09-02" (YYYY-DD-MM) and converting it to the specified datetime format(RFC3339) as specified in the official docs:
--since-time="": Only return logs after a specific date (RFC3339)
Here is the section responsible for the conversion:
date, err := time.Parse(time.RFC3339, "2023-09-02")
if err != nil {
log.Fatal(err)
}
since = date.String()
the error I get is:
parsing time "2023-09-02" as "2006-01-02T15:04:05Z07:00": cannot parse "" as "T"
I altered the format according to this article and altered the code to:
date, err := time.Parse("2006-01-02 15:04:05 -0700 MST", "2023-09-02")
the error that I get now is:
parsing time "2023-09-02" as "2006-01-02 15:04:05 -0700 MST": cannot parse "" as "15"
I understand that it's trying to parse the "15" of the hour but there isn't an hour provided. Is there a way to default it to midnight that day?
edit: after changing it to:
d, err := time.Parse("2006-01-02", since)
if err != nil {
log.Fatal(err)
}
sinceTime = d.Format(time.RFC3339)
sinceTime = 2023-09-02T00:00:00Z
but when I use that month in kubectl the command freezes
$ kubectl logs -n <NAME_SPACE> --container=<CONTAINER> -f --timestamps=true --since-time=2023-09-02T00:00:00Z --tail 500 -l app=<APP>
FIX:
d, err := time.Parse("2006-02-01", since)