Don't use SimpleDateFormat
it's long outdated and troublesome.
Use DateTimeFormatter
to parse the date.
fun parseDate() {
var formatter: DateTimeFormatter? = null
val date = "2021-11-03T14:09:31.135Z" // your date string
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX") // formatter
val dateTime: ZonedDateTime = ZonedDateTime.parse(date, parser) // date object
val formatter2: DateTimeFormatter =
DateTimeFormatter.ofPattern("EEEE, MMM d : HH:mm") // if you want to convert it any other format
Log.e("Date", "" + dateTime.format(formatter2))
}
}
Output: Wednesday, Nov 3 : 14:09
To use this below android 8 , use desugaring