wood burning stoves 2.0*
The moose likes Java in General and the fly likes date parse problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "date parse problem" Watch "date parse problem" New topic
Author

date parse problem

pradeep arum
Ranch Hand

Joined: Oct 01, 2003
Posts: 130
i am trying to give the parse() method the below string and it throws dateParse Exception , can somebody tell me what is the correct format...

String exceptionDate="07/10/96 08:46 ";

DateFormat dfobj= DateFormat.getDateInstance();
Date da= dfobj.parse(exceptionDate);

[ EJFH: We don't allow "URGENT" in subject lines. ]
[ October 15, 2004: Message edited by: Ernest Friedman-Hill ]

SCJP1.4,SCBCD
Failure is not when you fall down; its only when you fail to get up again.
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by pradeep arum:
DateFormat dfobj= DateFormat.getDateInstance();

From the JavaDocs for DateFormat, getInstance() with no parameters "gets the date formatter with the default formatting style for the default locale."

Therefore, your computer and JDK are not giving you a format of "MM/dd/yy HH:mm" or "dd/MM/yy HH:mm" (can't tell from your sample date which you expect). Most likely it is at least including the seconds part of the time. It could also be using a long format (spelled out month), for example.

If you want that format, specify it using something like
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
hi pradeep arum
You may be better to read something related to URGENT
About URGENT
It is quite useful for us to reference that how to ask question.


Francis Siu
SCJP, MCDBA
Surasak Leenapongpanit
Ranch Hand

Joined: May 10, 2002
Posts: 341
DateFormat and SimpleDateFormat Examples
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
Originally posted by pradeep arum:
i am trying to give the parse() method the below string and it throws dateParse Exception , can somebody tell me what is the correct format...

String exceptionDate="07/10/96 08:46 ";

DateFormat dfobj= DateFormat.getDateInstance();
Date da= dfobj.parse(exceptionDate);

[ EJFH: We don't allow "URGENT" in subject lines. ]

[ October 15, 2004: Message edited by: Ernest Friedman-Hill ]


Change to use SimpleDateFormate and Add pattern like this



SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: date parse problem
 
Similar Threads
range
Change format of date String-string
How to check if date/time was entered?
setProperty
Conversion of string to date