convert Milli Seconds To Time - Java java.util

Java examples for java.util:Millisecond

Description

convert Milli Seconds To Time

Demo Code


//package com.java2s;

import java.text.DateFormat;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import java.util.TimeZone;

public class Main {
    public static TimeZone timezone = TimeZone.getTimeZone("GMT+0");

    public static String convertMilliSecondsToTime(double milliSeconds) {
        // Create a DateFormatter object for displaying date in specified format.
        DateFormat formatter = new SimpleDateFormat("HH:mm:ss");
        formatter.setTimeZone(timezone);

        // Create a calendar object that will convert the date and time value in milliseconds to date. 
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis((long) milliSeconds);

        return formatter.format(calendar.getTime());
    }/*from  www.  ja v a  2s  . co  m*/
}

Related Tutorials