0

I am getting date in String as 09/16/2012 15:57. How do i convert it in java.util.Date

I have tried :

SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yy HH.mm.ss.SSS a");
dateFormat.parse(res.getString("stringdate"));

But getting unparseable exception

Plz suggest.

3
  • And the stack trace is ? Commented Aug 7, 2014 at 9:24
  • Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See How to create a Minimal, Complete, and Verifiable example. Commented Aug 7, 2014 at 9:26
  • possible duplicate of Java: unparseable date exception Commented Aug 7, 2014 at 12:17

3 Answers 3

6

You date time pattern is not correct. Try to match the input string

SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm");
Sign up to request clarification or add additional context in comments.

Comments

0
You date time pattern is not correct.Many of the datetime format is there
 Try to match correct input string

Example
String dateStr = "2011-09-19T15:57:11Z";
String pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'";
Date date = new SimpleDateFormat(pattern).parse(dateStr);

Patterns are

"yyyy.MM.dd G 'at' HH:mm:ss z" 2001.07.04 AD at 12:08:56 PDT

"EEE, MMM d, ''yy" Wed, Jul 4, '01

"h:mm a" 12:08 PM

"hh 'o''clock' a, zzzz" 12 o'clock PM, Pacific Daylight Time

"K:mm a, z" 0:08 PM, PDT

"yyyyy.MMMMM.dd GGG hh:mm aaa" 02001.July.04 AD 12:08 PM

"EEE, d MMM yyyy HH:mm:ss Z" Wed, 4 Jul 2001 12:08:56 -0700

"yyMMddHHmmssZ" 010704120856-0700

"yyyy-MM-dd'T'HH:mm:ss.SSSZ" 2001-07-04T12:08:56.235-0700

Comments

0

Your date pattern does not match the given date string. Try the following:

    SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm");
    dateFormat.parse(res.getString("stringdate"));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.