JavaScript will be divided, seconds, milliseconds converted to xx days xx hours xx seconds (any language common, most easy to understand)

Source: Internet
Author: User


1 // The incoming parameter is the total number of minutes. If it is the number of seconds, the number of milliseconds, you need to adjust the code of the // part of the total seconds here.
 2 function toDateDMS(minutes){
 3 // Convert minutes to days, hours, minutes, seconds
 4 if(minutes&&!isNaN(minutes)){
 5
 6 var t = parseFloat(minutes*60); // get the total number of seconds here
 7
 8 var d,h,m,s; // Define time, minute and second variables (day, hour, minute, second)
 9 
10 d = Math.floor(t/(24*3600)); // Calculate the number of days
11
12 // Calculate the total number of seconds that have been subtracted
13 t = t-(d*24*3600);
14 h = Math.floor(t/3600); // Calculate hours
15
16 // Calculate the total number of seconds that have been subtracted
17 t = t-(h*3600);
18 m = Math.floor(t/60); // Calculate the number of minutes
19
20 // Calculate the total number of seconds that have been subtracted (actually from top to bottom, where t is already subtracted from the number of hours)
21 t = t-(m*60);
22 s = t; // count seconds
23 return d+"day"+h+"hour"+m+"clock"+s+"second";
twenty four   }
25 return "-";
26 }

JavaScript will be divided, seconds, milliseconds converted to xx days xx hours xx seconds (any language common, most easy to understand)


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.