Errr, 46? There's no 46 here.
Anil,
you should look at the SimpleDateFormat class - it has most of what you need. The only thing it can't handle is the "singapore" part of your
string - which isn't part of the time anyway. So you can filter this part out before you try to parse the time with SimpleDateFormat. See here:
<code><pre>
String input="08:24:43.176 singapore Mon Mar 1 1993";
// Grabbing the time part is easy - it's just the first 12 chars, exactly
String timeStr = input.substring(0, 12);
// Grabbing the date is harder - the day of month may have 1 or 2 spaces
// (other parts may have varying length as well)
// So - count 4 space characters from end (we can't count from the beginning
// since the location may have additional spaces as well
// - e.g. "los angeles" instead of "singapore")
int length = input.length();
int lastPos = length;
for (int i = 0; i < 4; i++) {
lastPos = input.lastIndexOf(' ', lastPos - 1);
}
String dateStr = input.substring(lastPos); // includes 1 leading space
String combinedStr = timeStr + dateStr;
System.out.println("Filtered input string: " + combinedStr);
DateFormat df = new SimpleDateFormat("hh:mm:ss.SSS EEE MMM dd yyyy");
Date date = df.parse(combinedStr);
System.out.println("Parsed date: " + date);
</pre></code>
[This message has been edited by Jim Yingst (edited July 03, 2001).]