Results 1 to 4 of 4
  1. #1
    willemuk is offline Member
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default Time String to Seconds int

    My time values are minutes and seconds extracted from strings within a file. What I am having difficulty in doing is the conversion from "3:25" as a string to 205 seconds as an integer. My simple question would be then how is this achieved. So String to int conversion (in seconds). I attempted it already by using a delimiter to remove the ":" thus separating the minutes and seconds in an array but now I am stuck with how to proceed. any ideas would be greatly appreciated. Thanks

    // String to split.
    String str = "3:25";
    String[] tempString;

    // delimiter
    String delimiter = ":";

    // given string will be split.
    tempString = str.split(delimiter);

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Time String to Seconds int

    Do you not like or appreciate the help you already received?

    Cross posted at Time String to int seconds

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default Re: Time String to Seconds int

    So you now have an array of two Strings, each representing integers.
    The Integer API has a method or two that might be useful for your next step, which is turning the Strings into ints.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    willemuk is offline Member
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default Re: Time String to Seconds int

    Thank you very much Tolls that helped a lot. I have used the decode method to parse the string values to ints and so far it seems to be working but will do further tests to be sure. Thanks again

Similar Threads

  1. Appending Seconds to Time
    By reach2sudhakar in forum New To Java
    Replies: 9
    Last Post: 10-15-2010, 09:00 AM
  2. Replies: 4
    Last Post: 09-09-2010, 11:15 AM
  3. Replies: 3
    Last Post: 04-05-2010, 01:08 PM
  4. getting time elapsed in seconds
    By ali_sakar in forum New To Java
    Replies: 3
    Last Post: 03-06-2009, 08:37 AM
  5. measuring time in nano seconds
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-06-2007, 12:11 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •