File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Parsing error in DaterFormat.parse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Parsing error in DaterFormat.parse" Watch "Parsing error in DaterFormat.parse" New topic
Author

Parsing error in DaterFormat.parse

ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 230


DateFormat formatter = DateFormat.getDateInstance(iDateFormat, locale);

Date currentTime = formatter.parse(strInputDate);
where local value is - zh_HK [ HongKong] and value of input date is

2010年2月25日

i am geeting java.text.parseble Error

whats exaclty getDateInstance does when we pass loacal to it ,

is anything wrong in my code ?

help
Srikanth Nalam
Greenhorn

Joined: Feb 23, 2010
Posts: 20
Hello Ravindra,

You need to ensure that 'strInputDate' is as per the style 'iDateFormat' and locale 'zh_HK'

I prefer to create a SimpleDateFormat object with the pattern in which the date string is expected and then parse it.

ex:


Thanks & Regards,
Srikanth Nalam.
ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 230
You mean i need to pass input to

DateFormat format=new SimpleDateFormat("mm/dd/yyyy");
in my case

DateFormat format=new SimpleDateFormat(strInputDate);


??
Srikanth Nalam
Greenhorn

Joined: Feb 23, 2010
Posts: 20
No.
For the constructor you need to pass the pattern in which the date string is received.
For the parse method you need to pass the strInputDate
There is a mistake in the code i gave in earlier post. The method should be 'parse' not 'format'
Date date=format.format("12/30/2009");


ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 230
that means even i pass 2010年2月25日 to format.parse will it work ??
ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 230
pattarn i am geeting is Jan 26,2010

so what pattarn should i give in constuctor
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19785
    
  20

Check out SimpleDateFormat. Your string has the following parts:
- the month in short format. The month is M. Try using M, MM, MMM, MMMM etc and see what that does.
- a space
- the day of month. That's d. Try using d, dd, ddd etc and see what that does.
- a comma
- the year. That's y. Again, try using y, yy, yyy, yyyy etc and see what that does.

You may want to try formatting first. For example:
This will help you out with how many M's, d's and y's you need.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 230

i have defined patternd as
SimpleDateFormat date= new SimpleDateFormat("MMM dd, yyyy",locale);

. when when my broswer language is set to english

Date - Feb 26, 2010 System.out.println(date.format(new Date())); is printed as Feb 26, 2010
but when language ,local is fr_FR then it prints févr. 26, 2010 Dot . is inserted dont know why which gives unparseable error

how date works in case of internationalization ?
ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 230
reply someone
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parsing error in DaterFormat.parse