Reputation: 429
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))
}
}
Upvotes: 2
Views: 1760
Reputation: 429
I have found my Issue:
My pattern was wrong, I was meant to do this:
val inputFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
But Instead I was doing this:
val inputFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
Notice the single quotes with 'Z'
Upvotes: 2