• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

date parse problem

 
pradeep arum
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Surasak Leenapongpanit
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DateFormat and SimpleDateFormat Examples
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic