Parse a String to Date in Java -


I am trying to parse a string on a date, I have it:

 Code> Simple Data Format SDF = New Simple Format ("EEE MMM DD Yay HH: MM: SSZZZ"); Date = new date (); Try {date = sdf.parse (time); } Hold (ParseException e) {e.printStackTrace (); }   

The string to pars is:

  Sun Jul 15 2012 12:22:00 GMT + 0300 (FLE Daylight Time)   

I followed it

I am sure that I have done everything from the book. But it is giving me ParseException .

  java.text.ParseException: unused date: "Sun July 15 2012 12:22:00 GMT + 0300 (FLE Daylight Time)"   

I What's wrong? Pattern which I have tried:

  EEEMMD DD yyyy HH: mm: SS zzz EEE MMM DD yyyy HH: mm: SS zZ (zzzz)   < / Div> 

You are matching the pattern to z and Z . If you ignore (FLE daylight time) , because it has the same information as GMT + 0300 , then the problem is that SimpleDateFormat Whether it wants either GMT + 0300 or GMT + 03: 00 . The previous version can be parsed like this:

  string time = "Sun July 15 2012 12:22:00 GMT + 03: 00 (FLE Daylight Time)"; SimpleDateFormat SDF = New Simple Format ("EEE MMM DD YYYY HH: MM: SSZZ"); Date date = sdf Prs (time);  [edit]  
In light of other posts about the strings of your time, it is probably possible because your time string contains conflicting information or mixed formats

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -