I have a date in String format, which I parse using SimpleDateFormat, but to my surprise I keep getting java.text.ParseException: Unparseable date: Error.
I thought I was getting the pattern wrong, but I looked closely & i don't think so, I'm wondering what my issue might be:
I Keep getting
E/FormatFormDate: java.text.ParseException: Unparseable date: "2019-02-25T22:43:23.213Z"
This is my code below:
var clean = "2019-02-25T22:43:23.213Z"
val inputFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
val outputFormatTime = "HH:mm"
val DATE_TIME_ONLY = SimpleDateFormat(outputFormatTime, Locale.getDefault())
if (clean != "") {
try {
val parseDate = SimpleDateFormat(inputFormat, Locale.getDefault()).parse(clean)
clean = DATE_TIME_ONLY.format(parseDate)
Log.d("TAG", clean)
} catch (e: ParseException) {
Log.e("FormatFormDate", Log.getStackTraceString(e))
}
}
SimpleDateFormatand friends, and adding ThreeTenABP to your Android project in order to usejava.time, the modern Java date and time API. It is so much nicer to work with.