How to Convert Milliseconds to Time in Java

This is the simple and interesting java program for logic building. The java program converts the Milliseconds into standard time e.g. 7000000 milliseconds = 1 hour 56 minute and 40 seconds.

Source Code 

package packaga;
public class millesecToTime {
/**
     * @param args the command line arguments
     */
public static void main(String[] args) {
long millis = 7000000;
long second = (millis / 1000) % 60;
long minute = (millis / (1000 * 60)) % 60;
long hour = (millis / (1000 * 60 * 60)) % 24;

String time = String.format("%02d:%02d:%02d:%d", hour, minute, second, millis);
System.out.println(millis+" ms = "+hour+" hours "+ minute+"minute "+ second+"second" );
System.out.println(""+time);
}
}

Output of the Program

Convert Milliseconds to Time in Java

 

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment