• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parsing error in DaterFormat.parse

 
ravindra patil
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
ravindra patil
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that means even i pass 2010年2月25日 to format.parse will it work ??
 
ravindra patil
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pattarn i am geeting is Jan 26,2010

so what pattarn should i give in constuctor
 
Rob Spoor
Sheriff
Pie
Posts: 20659
64
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
ravindra patil
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
reply someone
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic