Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

resolving java.lang.NumberFormatException

 
neha priya
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello everyone,


i have a string of the form "03July2010 13:50:50 "
i want to convert this string to number(integer) so that i am able to
apply relational operators like(>,<,>=,=) to get the result.

could anyone help me out with this.

thanks.
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to look at the SimpleDateFormat class, where you can parse the Date/Time string into a java.util.Date - which you then can get as a long.
 
neha priya
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply...am actually new to java...can you please try explaining my query through a java code as in how do i use java.uti.Date and convert to long.
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You create a SimpleDateFormat object on which you set a Date/Time pattern matching your string input (see the SimpleDateFormat API for a list of available pattern elements, and how they are used), then you parse your string date/time, and finally you get the date/time as a long from the Date object.

Like this sample:

 
neha priya
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic