Unparseable date что за ошибка
Java: unparseable date exception
While trying to transform the date format I get an exception:unparseable date and don’t know how to fix this problem.
I am receiving a string which represents an event date and would like to display this date in different format in GUI.
What I was trying to do is the following:
is dummy. I would like to get a date string in the following format:
and the input String example is the following:
Does anyone know how to convert the example date (String) above into a String format dd.MM.yyyy HH:mm:ss?
Edit: I fixed the wrong input date format but still it doesn’t work. Above is the pasted method and below is the screen image from debugging session.
#Update I ran
and there is UTC String in the array. It’s a strange problem.
I did a dirty hack that works:
But still I would prefer to transform the original input without cutting timezone away.
This code is written for Android phone using JDK 1.6.
3 Answers 3
Update: Okay, I did a test:
This correctly prints:
I encountered this error working in Talend. I was able to store S3 CSV files created from Redshift without a problem. The error occurred when I was trying to load the same S3 CSV files into an Amazon RDS MySQL database. I tried the default timestamp Talend timestamp formats but they were throwing exception:unparseable date when loading into MySQL.
This from the accepted answer helped me solve this problem:
By the way, the «unparseable date» exception can here only be thrown by SimpleDateFormat#parse(). This means that the inputDate isn’t in the expected pattern «yyyy-MM-dd HH:mm:ss z». You’ll probably need to modify the pattern to match the inputDate’s actual pattern
The key to my solution was changing the Talend schema. Talend set the timestamp field to «date» so I changed it to «timestamp» then I inserted «yyyy-MM-dd HH:mm:ss z» into the format string column view a screenshot here talend schema
I had other issues with 12 hour and 24 hour timestamp translations until I added the «z» at the end of the timestamp string.
java.text.ParseException: Unparseable date
I am getting a parsing exception while I am trying the following code:
Exception in thread «main» java.text.ParseException: Unparseable date: «Sat Jun 01 12:53:10 IST 2013» at com.ibm.icu.text.DateFormat.parse(DateFormat.java:510)
Input: Sat Jun 01 12:53:10 IST 2013
Expected output: Jun 01,2013 12:53:10
9 Answers 9
Your pattern does not correspond to the input string at all. It is not surprising that it does not work. This would probably work better:
Then to print with your required format you need a second SimpleDateFormat:
Update your format to:
ISO 8601
Instead a format such as yours, use ISO 8601 standard formats for exchanging date-time values as text.
The java.time classes use the standard ISO 8601 formats by default when parsing/generating strings.
Proper time zone name
Your IST could mean Iceland Standard Time, India Standard Time, Ireland Standard Time, or others. The java.time classes are left to merely guessing, as there is no logical solution to this ambiguity.
java.time
The modern approach uses the java.time classes.
Define a formatting pattern to match your input strings.
About java.time
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.