Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How to convert

  1. #1
    Junior Member torstensson's Avatar
    Join Date
    Oct 2011
    Thanked 0 Times in 0 Posts

    Default How to convert

    /* Hi guys, im been working a while with following code and now im really stuck
    * The code asks the user to put in the startime for a runner in a race and then the finishing time.* Then it converts the hh/mm/ss into seconds.
    * The last step is to convert the seconds into hh/mm/ss to show the total amount of time it took* for the runner to complete the track.
    * So, how do i convert the seconds into hh/mm/ss??????? ;(

    package test;

    import javax.swing.*;

    * @author torstensson
    public class test {

    * @param args the command line arguments
    public static void main(String[] args) {

    //Starttime input

    String strT1 = JOptionPane.showInputDialog("Starttime hour" );
    String strM1 = JOptionPane.showInputDialog("Starttime min" );
    String strS1 = JOptionPane.showInputDialog("Starttime sec" );

    System.out.println("Starttime:\n" + "---------\n" +
    "Hour: " + strT1 + "\n" + "Min: " + strM1 + "\n" +
    "Sec: " + strS1 + "\n");

    //Finishingtime input

    String strT2 = JOptionPane.showInputDialog("Finishing hour" );
    String strM2 = JOptionPane.showInputDialog("Finishing min" );
    String strS2 = JOptionPane.showInputDialog("Finishing sec" );

    System.out.println("Finishingtime :\n" + "---------\n" +
    "Hour: " + strT2 + "\n" + "Min: " + strM2 + "\n" +
    "Sec: " + strS2 + "\n");

    //Converting variables

    int intT1 = Integer.parseInt(strT1);
    int intM1 = Integer.parseInt(strM1);
    int intS1 = Integer.parseInt(strS1);

    int intT2 = Integer.parseInt(strT2);
    int intM2 = Integer.parseInt(strM2);
    int intS2 = Integer.parseInt(strS2);

    //Calculation of input

    int sumintT2 = intT2 * 3200;
    int sumintM2 = intM2 * 60;

    int sumintT1 = intT1 * 3200;
    int sumintM1 = intM1 * 60;

    int totSek = sumintT2 + sumintM2 - sumintT1 - sumintM1;



    First there was big bang, then there was Internet.

  2. #2
    Junior Member
    Join Date
    Nov 2011
    My Mood
    Thanked 1 Time in 1 Post

    Default Re: How to convert


    To get your seconds back into hh::mm:ss why dont u take your total number of seconds totSek and divide by 60 to give u the number of minutes. Then if u use the modulas operator % to do totSek modulas 60 that gives u the remainder of seconds.

    Doing that will give u your minutes and seconds and the same principle applies for minutes to hours.

    Hope this helps

  3. #3
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    My Mood
    Thanked 82 Times in 78 Posts
    Blog Entries

    Default Re: How to convert

    This post is duplicate.

Similar Threads

  1. Convert DOC,XLS to PDF with Java
    By comm in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: July 2nd, 2013, 04:10 AM
  2. Convert to JOptionPane
    By ahzim8 in forum Java Theory & Questions
    Replies: 1
    Last Post: March 10th, 2011, 09:52 AM
  3. Convert C++ to Java ?
    By doaa in forum Java Theory & Questions
    Replies: 1
    Last Post: January 15th, 2011, 10:52 AM
  4. Conversion of string into integer in Java
    By JavaPF in forum Java Programming Tutorials
    Replies: 17
    Last Post: January 23rd, 2010, 09:33 AM
  5. convert GSM to PCM (wav)
    By cilang in forum Java Theory & Questions
    Replies: 4
    Last Post: August 7th, 2009, 03:46 AM