Milliseconds converted to days, hours, minutes, seconds

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.