I can do a function that converts the milliseconds. I know that 1000 milliseconds is 1 second, that 60 seconds is a minute, that 60 minutes is an hour.
public static int milisegundos2tiempo(int ms)
{
int mili = ms%1000; ms -= mili; ms /= 1000;
int segs = ms%60; ms -= segs; ms /= 60;
int mins = ms%60; ms -= mins; ms /= 60;
int horas = ms;
return horas*1000*100*100 + mins*1000*100 + segs*1000 + mili;
}
It will return a strange half whole, do not worry, I'll explain it to you:
If you return 223344555, it means that they are 22 hours with 33 minutes with 44 seconds and 555 milliseconds ... This can return a number of hours greater than 24 ... In that case, you only have to change int horas = ms;
int horas = ms%24;
... It is also recommended some function to convert that strange number to a String and format it with bars or hyphens (/ or -).
Since you need to return a Date
, I have decided to investigate, and found a link that explains that. Editing a bit, I have the answer you need.
import java.util.Date;
public class Programa {
public static void main (String []args){
System.out.print ("Ingrese la cantidad de milisegundos:\n");
Scanner teclado = new Scanner(System.in);
int n = teclado.nextInt();
teclado.close();
int res = milisegundos2tiempo(n);
Date fecha1;
fecha1 = new Date(100,0,0,res%10000000,res%100000,res%1000);
System.out.println( fecha1.toGMTString() );
}
}