I get a datetime string from an C# API that looks like this "2021-05-07T08:58:15.993". I am trying to convert it to "2021-05-07 08:58 AM" for my android app. I am using this code:
fun convertStringToDate(stringDate: String): LocalDate? {
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm ", Locale.ENGLISH)
val date = LocalDate.parse(stringDate, formatter)
return date
}
but it gives me an error of DateTimeParseException "2021-05-07T08:58:15.993" could not be parsed at index 10.
Index 10 is the 'T' character. I could just hack it and just remove the T and remove the .993, but, what if the date format changes from the API?