It appears that Kotlin is very specific regarding the formats of Date. I am receiving a string in this "Jan 1 2023 12:00AM"
and wanted to convert it into this "2023-01-01 00:00:00.0"
format. I looked around but couldn’t find a solution.
fun FormatDateTime(dateTimeString: String): String{
val DATE_FORMAT = DateTimeFormatter.ofPattern("MMM dd uuuu")
var dat = dateTimeString.substring(0, dateTimeString.length-7).trim() //Removing ' 12:00AM' part
val changeDate = LocalDateTime.parse(dat, DATE_FORMAT)
//After getting the date, reformat it again to '2023-01-01 00:00:00.0'
return "" //return formatted date string, currently returning empty string
}
But its failing. Is there any way to achieve that?
3