converting string time to time stamp
Hi,
I need to convert time string to TimeStamp.
This is what I am doing right now.
public Timestamp getTimeForPageMetrics(String date,String time)
{
int month=Integer.parseInt(date.substring(0,2));
int day=Integer.parseInt(date.substring(3,5));
int year=Integer.parseInt(date.substring(6,10));
int hours=Integer.parseInt(time.substring(0,2));
int minutes=Integer.parseInt(time.substring(3,5));
int seconds=Integer.parseInt(time.substring(6,8));
Calendar c=new GregorianCalendar();
c.set(Calendar.HOUR,hours);// 0..23
c.set(Calendar.MINUTE,minutes);
c.set(Calendar.SECOND, seconds);
c.set(year,month-1,day,hours,minutes,seconds);
//System.out.println("U r in getTimeForPageMetrics and value in getTimeForPageMetrics"+c.getTime().toString());
return new Timestamp(c.getTime().getTime());
}
But iget the following NumberFormatException
java.lang.NumberFormatException: For input string: "10/0"
Any advice is highly appreciated
[1058 byte] By [
poltona] at [2007-10-3 6:26:17]

Rather than try to piece out the date and time parts yourself, just use a java.text.SimpleDateFormat object, tell it what format the date/time is in, and tell it to parse the string itself.
Besides that, is it not obvious to you that the string "10/0" does not represent an integer value? So obviously if you wanted to fix your code you'd need to get the parsing done right so that you try to parse the right parts of the string.
But first go with what I said in the first paragraph, and stop reinventing the wheel.
P.S. I find it odd that you knew about SimpleDateFormat in a post from a while back:
http://forum.java.sun.com/thread.jspa?threadID=749638
and somehow decided to reinvent the wheel anyway now.
I dont know how any advice will be highly appreciated can mean
"Any advice will be utterly ignored"...
It means an advice would be most welcome. as it might solve my problem.
And it has actually been solved.because the follwing works fine
Any advice will be utterly ignored
SimpleDateFormat sdf=new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
Date d=sdf.parse(new StringBuffer(date).append(" ").append(new StringBuffer(time)).toString());
timeStamp=new Timestamp(d.getTime());
thanks again!!!!!
> I dont know how any advice will be highly appreciated
> can mean
> "Any advice will be utterly ignored"...
Well, it's good that you finally came back to say a simple "thank you". What I meant of course was that in a typical conversation if someone asks a question and a helpful answer is given, normally one would expect some kind of reply in about the same turnaround time that occurred between the question and the answer. It had been 2 days ago that you were answered, and we're not talking about a conversation between 2 rocks here, but rather people. 2 days between rocks' conversations might be fine, but not for people.
But anyway, you did say thanks though I felt some sarcasm coming from it. You're welcome anyway.