Original: Milliseconds converted to days, hours, minutes, seconds
Converts the number of milliseconds or two date types to * days * hours * minutes * seconds, which should be used frequently when calculating time periods.
Remember that an ACM problem is from a timing method A to another timing method B, the idea is as follows: The total time will not change, 1s is 1s, but the hours, minutes, Tian Deng contains a different number of seconds, so first convert a to the total number of seconds sumsec, and then use sumsec to draw B time; it's simple, No one in our association wants to come out, I have been thinking about the reason, is not because of learning to learn the creative.
Questions about formatting date types are outside the scope of this article, and are available to readers themselves.
/** * * @param the number of milliseconds to convert * @return the number of milliseconds converted to * days * hours * minutes * seconds format * @author Fy.zhang */public static St Ring formatduring (Long MSS) {Long days = MSS/(+ *); long hours = (MSS% (1000 * 60 * 60 * 24))/(1000 * Long minutes = (MSS% (+ *))/(+ +), long seconds = (MSS% (+ *))/1000;return days + "D Ays "+ hours +" hours "+ minutes +" minutes "+ seconds +" seconds ";} /** * * @param beginning of the begin period * @param end of time period * @return The time between the two date type data entered * days * hours * minutes * seconds format Display * @author Fy.zhang */public static String formatduring (date begin, date end) {return formatduring (End.gettime ()-Begin.get Time ());}
Thanks to the sharer, I did not change this code to reflect the respect of the original author because I couldn't find the original link.
Milliseconds converted to days, hours, minutes, seconds