I have a datetime string in json with the below format
/Date(315513000000+0530)/
I would like to convert this into golangs time.Time
format. I tried passing this string to the below function
func parseDateField(dateInput string) (int64, error) {
startIdx := strings.Index(dateInput, "(")
if startIdx == -1 {
return 0, errors.New("Error parsing quote Date. '(' symbol not found")
}
endIdx := strings.Index(dateInput, "+")
if endIdx == -1 {
return 0, errors.New("Error parsing quote Date. '+' symbol not found")
}
dateStr := dateInput[startIdx+1 : endIdx]
date, err := strconv.ParseInt(dateStr, 10, 64)
if err != nil {
fmt.Printf(" err :
%+v
", err)
return 0, err
}
tm := time.Unix(date, 0)
fmt.Printf("
time :
%+v
", tm)
dateAsEpoch := int64(date / 1000)
fmt.Printf("
dateAsEpoch :
%+v
", dateAsEpoch)
return dateAsEpoch, nil
}
I'm getting the below outputs
time :
11968-03-18 01:30:00 +0530 IST
dateAsEpoch :
315513000
I'm guessing the parsing isnt done right - what am i doing wrong?