I'm trying to display an incoming ISO Date like (2021-02-15T00:00:00.000Z) to a Textview in the following format: "dd MM yyyy". But I get the following error when parsing the date.
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Caused by: java.text.ParseException: Unparseable date: "2021-02-15T00:00:00.000Z"
at java.text.DateFormat.parse(DateFormat.java:362)
Here is the Kotlin code:
val format = SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss'Z'",
Locale.getDefault()
)
val initialConvertedDate = format.parse(customfield.value)
val simpleDateFormat = SimpleDateFormat(
"dd MM yyyy",
Locale.getDefault()
)
val finalDate = simpleDateFormat.format(initialConvertedDate)
tv2.text = finalDate