0

I'm having a problem with parsing my date. I have the date "Mittwoch, 28. 06. 2017" as a string and using the following code for parsing it:

date = new SimpleDateFormat("EEEE, dd. MM. yyyy", Locale.GERMAN).parse("Mittwoch, 28. 06. 2017");

But this is still giving me the unparseable date error.

If I run it on another system, it's working fine.

Thank you very much

EDIT:

    java.text.ParseException: Unparseable date: "Mittwoch, 28. 06. 2017"
        at java.text.DateFormat.parse(DateFormat.java:366)
        at Download.StartDownload(Download.java:88)
        at Download.main(Download.java:42)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
der.java:58)
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
der.java:58)
Caused by: java.lang.NullPointerException
        at java.util.Calendar.setTime(Calendar.java:1770)
        at java.text.SimpleDateFormat.format(SimpleDateFormat.java:943)
        at java.text.SimpleDateFormat.format(SimpleDateFormat.java:936)
        at java.text.DateFormat.format(DateFormat.java:345)
        at Download.StartDownload(Download.java:94)
        at Download.main(Download.java:42)
        ... 5 more

EDIT: I was using a older java version that caused the error.

SO1992
  • 127
  • 1
  • 13
  • It should tell you why it can't unparse that. Post that error so we can help you. EDIT : **post the stacktrace as text please** – AxelH Jun 29 '17 at 10:41
  • post error msg as well. – Sanjay Jun 29 '17 at 10:42
  • `Cause by NullPointerException`, that's a start... What is the java version ? – AxelH Jun 29 '17 at 10:46
  • The NullPointerException is just the following error. It's version 1.8.0_05 – SO1992 Jun 29 '17 at 10:48
  • 1
    I cannot reproduce that: It works both with `EEEE` and `EEE` java 1.8.0_66 – Antoniossss Jun 29 '17 at 10:51
  • 1
    It works for me too, but on another system. If I'm copying the .jar file to the system where I need to run this program, it gives me this error. – SO1992 Jun 29 '17 at 10:53
  • check if issue if similar to https://stackoverflow.com/questions/19861642/date-format-parse-exception-eee-mmm-dd-hhmmss-z-yyyy – Sanjay Jun 29 '17 at 10:56
  • 1
    Thank you everybody. The java version was the error. It's working now. Didn't expect to get these errors just because of an slightly older version. – SO1992 Jun 29 '17 at 11:00
  • You might need to debug on that system to see what is happening `SimpleDateFormat.parse(String text, ParsePosition pos)`, this doesn't accept your format and the `DateFormat` throw at you an exception. – AxelH Jun 29 '17 at 11:00
  • 1
    You may want to post your finding as an answer, including information about the Java version where it doesn’t work and the version where it works, for everyone to learn from. I shall be happy to upvote such an answer. @SO1992 – Ole V.V. Jun 29 '17 at 11:15
  • Since the solution was a newer Java version (and even if it wasn’t), I recommend you do yourself the favour of discarding the outdated classes `Date` and `SimpleDateFormat` and instead use the modern Java date and time API: `LocalDate date = LocalDate.parse("Mittwoch, 28. 06. 2017", DateTimeFormatter.ofPattern("EEEE, dd. MM. yyyy", Locale.GERMAN));`. Contrary to `Date` `LocalDate` comes without time of day and time zone and thus more clearly models what you want and leaves a lot less room for confusion. – Ole V.V. Jun 29 '17 at 11:24

1 Answers1

0

Try with EEE instead of EEEE

 date = new SimpleDateFormat("EEE, dd. MM. yyyy", Locale.GERMAN).parse("Mittwoch, 28. 06. 2017")
Sanjay
  • 1,078
  • 11
  • 15