MikeD
Posts: 15
Nickname: mike
Registered: Apr, 2002
|
|
Full Question: Parsing Date/Time using SimpleDateFormat (or other)
|
Posted: Apr 29, 2002 11:39 AM
|
|
Sorry, hit 'post' instead of 'preview'. Here is the full question.
Hi, I am having trouble parsing a Date/Time String into a Date object. It is no trouble to parse a date string, or to parse a date/time string with a parser that ignores the time portion, but when using a parser that should pick up the time portion, I get a ParseException.
Works: try{ //SimpleDateFormat simp = new SimpleDateFormat ("MM/dd/YYYY hh:mm:ss a"); SimpleDateFormat parse = new SimpleDateFormat("MM/dd/yyyy"); SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a"); String dateTime = "7/10/1996 4:50:00 PM"; Date parsed = parse.parse(dateTime); System.out.println("formatted: " + formatter.format(parsed)); } catch(ParseException e){ System.out.println("Caught " + e); }
Doesn't work: try{ SimpleDateFormat parse = new SimpleDateFormat("MM/dd/YYYY hh:mm:ss a"); //SimpleDateFormat parse = new SimpleDateFormat("MM/dd/yyyy"); SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a"); String dateTime = "7/10/1996 4:50:00 PM"; Date parsed = parse.parse(dateTime); System.out.println("formatted: " + formatter.format(parsed)); } catch(ParseException e){ System.out.println("Caught " + e); }
Any suggestions?
Thanks, Mike
|
|