Results 1 to 5 of 5
  1. #1
    Basit56 is offline Member
    Join Date
    Aug 2009
    Posts
    48
    Rep Power
    0

    Default Convert microseconds to seconds

    Hi,
    Hope you all will be fine.I know it's a very basic question but i don't know why i am unable to doing it. Anyways i want to find a length of a .wav file, for this, i use this code but it returns length in microseconds

    Java Code:
     System.out.println( clip.getMicrosecondLength() );
    and the output is

    5875000

    i want this to be in seconds means if i convert this to seconds it becomes 5.875 sec, so i want that when i execute this line it gives me only 6 sec after rounding of or 5 or 20 sec only, means only int value no decimal value.

    I also tried this
    Java Code:
    System.out.println( clip.getMicrosecondLength()/0.000001 );
    and also

    Java Code:
    System.out.println( (clip.getMicrosecondLength()/0.000001)%60 );
    but i can't get the desired result. Please help

    Thank you

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Read the API specs for the Math.round method.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Quote Originally Posted by Fubarable View Post
    Maybe my math is off, but my brain tells me that

    5875000 ms / 1000 = 5875 seconds
    There is a millisecond vs microsecond thing going on there.

  5. #5
    Basit56 is offline Member
    Join Date
    Aug 2009
    Posts
    48
    Rep Power
    0

    Default

    Hi,
    Thank you to all for your help. Really it's very simple. Simply

    Java Code:
     /**
             * Conversion in seconds. Since 
             * 1 microsecond = 10^(-6) sec
             * 1 microsecond = 1/1000000 sec
             */
            System.out.println("seconds: " + (clip.getMicrosecondLength()/1000000) );
    Thank you

Similar Threads

  1. Difference in seconds between two times
    By jazzy639 in forum New To Java
    Replies: 11
    Last Post: 09-26-2009, 07:58 PM
  2. getting time elapsed in seconds
    By ali_sakar in forum New To Java
    Replies: 3
    Last Post: 03-06-2009, 09:37 AM
  3. Need help with calculate the number of seconds
    By ProUnbeatable in forum New To Java
    Replies: 5
    Last Post: 10-11-2008, 04:07 AM
  4. Replies: 1
    Last Post: 06-30-2008, 08:14 AM
  5. measuring time in nano seconds
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-06-2007, 01:11 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
  •