• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Regd. time

 
Ranch Hand
Posts: 527
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to retrieve date and time from the following line,
08:24:43.176 singapore Mon Mar 1 1993
Howz going to do. I tried using Calendar and DateFormat, is there anyway??
Thanks,
Anil
 
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what does 46 stand for?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
rani bedi
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry i meant 176?
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I assumed it was milliseconds, considering its postion, and the use of the decimal point.
 
Did Steve tell you that? Fuh - Steve. Just look at this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic