convert Milli Seconds To Simple Time - Java java.util

Java examples for java.util:Millisecond

Description

convert Milli Seconds To Simple 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 convertMilliSecondsToSimpleTime(double milliSeconds) {
        // Create a DateFormatter object for displaying date in specified format.
        DateFormat formatter = new SimpleDateFormat("HH:mm");
        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  w  w w  .  j  a v  a  2 s. c om
}

Related Tutorials