aspose file tools*
The moose likes Beginning Java and the fly likes resolving java.lang.NumberFormatException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "resolving java.lang.NumberFormatException" Watch "resolving java.lang.NumberFormatException" New topic
Author

resolving java.lang.NumberFormatException

neha priya
Ranch Hand

Joined: Jul 03, 2010
Posts: 62
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

Joined: Oct 12, 2001
Posts: 1179

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.


Regards, Rene Larsen
Dropbox Invite
neha priya
Ranch Hand

Joined: Jul 03, 2010
Posts: 62
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

Joined: Oct 12, 2001
Posts: 1179

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

Joined: Jul 03, 2010
Posts: 62
thanks a lot
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: resolving java.lang.NumberFormatException