I am facing an issue whenever I am trying to parse the string. Here is the code
val date_ = "Wed Mar 29 15:21:00 IST 2022"
const val DF_MMM_dd_HH_mm_ss_z_yyyy = "EEE MMM dd HH:mm:ss z yyyy"
const val DF_dd_MMM_yyyy_ = "dd MMM, yyyy"
fun getDateFormatted(date: String, fromFormat: String, toFormat: String): String {
val fromDateFormat = SimpleDateFormat(fromFormat, Locale.getDefault())
val toDateFormat = SimpleDateFormat(toFormat, Locale.getDefault())
return try {
toDateFormat.format(fromDateFormat.parse(date))
} catch (e: Exception) {
date
}
}
But I am getting java.text.ParseException: Unparseable date:"Wed Mar 29 15:21:00 IST 2022" error. How can I resolve this? Thank in advance.