Results 1 to 3 of 3
  1. #1
    sm123 is offline Member
    Join Date
    Mar 2010
    Posts
    11
    Rep Power
    0

    Default Convert string hh:mm to milliseconds

    Hi,

    I have a String in format hh:mm (e.g. 13:35) which I want to convert to milliseconds. Please suggest how to do that?


    Thanks,

  2. #2
    programmer_007's Avatar
    programmer_007 is offline Senior Member
    Join Date
    Aug 2009
    Posts
    125
    Rep Power
    0

    Default

    is this the thing u are looking for !!

    Java Code:
    import java.util.Scanner;
    
    public class Sample {
    	public void getConverted(String s)
    	{
    		String[] c = s.split(":");
    		int hour = Integer.parseInt(c[0]);
    		int mint = Integer.parseInt(c[1]);
    		//Separeated and converted into integer.
    		System.out.println(hour);
    		System.out.println(mint);
    		
    		/*do maths here to calculate the milliseconds.
    		 * 
    		 * 
    		 * 
    		 */
    	}
    	
    	public static void main(String []args)
    	{
    		Sample s = new Sample();
    		s.getConverted("11:11");//passs any string from here.
    	}
    
    }

  3. #3
    programmer_007's Avatar
    programmer_007 is offline Senior Member
    Join Date
    Aug 2009
    Posts
    125
    Rep Power
    0

    Default

    s.getConverted("11:11");//passs any string from here
    dont pass aa:bb kind of things.. if passing prepare for NumberFormatException.

Similar Threads

  1. How to convert a string into a BigInteger
    By valery in forum New To Java
    Replies: 4
    Last Post: 09-13-2011, 01:32 PM
  2. convert String to Double
    By azurovyhrosik in forum CLDC and MIDP
    Replies: 5
    Last Post: 10-22-2008, 02:46 AM
  3. convert InetAddress to a string
    By hunterbdb in forum New To Java
    Replies: 4
    Last Post: 10-18-2008, 09:50 AM
  4. convert string to a double?
    By javaMike in forum Advanced Java
    Replies: 2
    Last Post: 11-27-2007, 03:10 AM
  5. convert string to float
    By miss_dot in forum NetBeans
    Replies: 1
    Last Post: 11-14-2007, 11:26 PM

Posting Permissions

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