0

I m new on android and i m not very good at english , so i try to be brief.

I search for hours on internet but get nothing! Here is a file image:

enter image description here

and I want to retrieve the second string (e.g "12:34:20.421"). please i need your help and excuse me for not putting too much details

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
Tete Tete
  • 23
  • 3

3 Answers3

0

If you just need the current time I would simply do something like this:

SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss:SSS");
String currentDateandTime = sdf.format(new Date());
0

try to use regex, I think that there is a better pattern than the one presented here, but it solves the problem.

    Pattern p = Pattern.compile("([0-9]+:[0-9]+:[0-9]+\\.[0-9]+).*");
    Matcher m = p.matcher("12-25 12:34:20.421 D/CallCard( 3454): updateForegroundCall()...");

    if (m.find()) {
        Log.i(TAG, m.group(1));

    }
medhdj
  • 1,168
  • 10
  • 17
  • thanks a lot !!! so i just want to return the entire second string , 12:34:20.421 in this case .So What have i to do ? what does m.group(1) exactly return ? i guess 12 (not the first one but the second) in that case , isn't it? – Tete Tete Dec 29 '14 at 00:46
  • `m.group(1)` returns the whole time entry, in this case 12:34:20.421 – medhdj Dec 29 '14 at 10:07
0

Are the dates always going to be 5 characters followed by space? Will January 9 be 01-09? I'm guessing yes. If you've got one line read into a string called someText, then:

timeStr = someText.substring(6,12)

EDIT: Hah, the OP noted that passing (6,12) was not right [would've been for JavaScript substr()]. It should have been (6,18).

wwfloyd
  • 312
  • 3
  • 11
  • thanks for your answers ... Yes January 9 is 01-09 and that's what i know on the line , now i want to get the second string which is unknown for me and is in this case "12:34:20.421" for the first line. I need more explanation about your answers , please. – Tete Tete Dec 28 '14 at 23:21
  • timeStr = someText.substring(6,12); You'd be taking that entire line into someText. The substring method says to grab characters starting at position 6 (they start at 0), and get 12 characters, the length of your desired time text, stored into timeStr. Try it. And please mark my answer correct, if it works for you. – wwfloyd Dec 28 '14 at 23:39
  • Thanks a lot Bro .. it works fine , but it's rather someText.substring(6,18) instead of Substring(6,12) in my case. thanks again :) – Tete Tete Dec 29 '14 at 02:12
  • Hey thanks for the note, and the points. Yeah, I did make a boo-boo there. I was thinking about the JavaScript substr() method. I'll add a correction , for anyone finding this later. – wwfloyd Dec 29 '14 at 04:24