java - Formatting time properly from miliseconds -


i timing event this:

seconds = system.currenttimemillis() / 1000; // happens here time = system.currenttimemillis() / 1000 - seconds; 

and have attempted format it:

string time = string.format("%d min, %d sec",     timeunit.milliseconds.tominutes(time),     timeunit.milliseconds.toseconds(time) -     timeunit.minutes.toseconds(timeunit.milliseconds.tominutes(time)));  

and results don't make sense, minutes thousands seconds seem normal numbers. proper way format time?

long milliseconds = system.currenttimemillis()%1000; long seconds = (system.currenttimemillis()/1000)%60; long minutes = (system.currenttimemillis()/(60*1000))%60; long hours = (system.currenttimemillis()/(60*60*1000)); 

leave out whatever parts don't want , remove modulus highest 1 do.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -