Search code examples
blackberry

Blackberry: how to convert time from String in "hhhh:mm:ss.ss" to "mm:ss" formate


I have a String with time and I want to convert it to other format. I try several soulutions and some of them was a ridiculous as convert string to char array and find numbers to colons etc. But I fail in that and I haven't enough time to found way by themselves.

Can you give me a solution? This convertaion not usual but probably you have got a solution. Thanks.


Solution

  • The format "hhhh:mm:ss.ss" seems unusual. But if you use any standard date format then you can use following code segments:

    SimpleDateFormat sd = new SimpleDateFormat("hh:mm");
    String time = sd.formatLocal(HttpDateParser.parse("2010-03-27 09:45:10"));
    

    But if you prefer raw string processing then you can use some like this:

    String input = "hhhh:mm:ss.ss";     
    String output = input.substring(input.indexOf(':') + 1, input.indexOf('.'));