• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Parsing error in DaterFormat.parse

 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
pattarn i am geeting is Jan 26,2010

so what pattarn should i give in constuctor
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
reply someone
 
There are no more "hours", it's centi-days. They say it's better, but this tiny ad says it's stupid:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic