3
I’m trying to put together a script that turns a number x of hours into weeks weeks hours minutes seconds
only that there is a problem all scripts I found return by ex c vc has 1 week it returns 1 week 7 days x hours and so on.
it would have to round or close. if it is difficult only the days serve
the script I’m trying to use is more or less this
function calcula(){
/ Set the unit values in milliseconds.
var msecPerMinute = 1000 * 60;
var msecPerHour = msecPerMinute * 60;
var msecPerDay = msecPerHour * 24;
// Set a date and get the milliseconds
var date = new Date('6/15/1990');
var dateMsec = date.getTime();
// Set the date to January 1, at midnight, of the specified year.
date.setMonth(0);
date.setDate(1);
date.setHours(0, 0, 0, 0);
// Get the difference in milliseconds.
var interval = dateMsec - date.getTime();
// Calculate how many days the interval contains. Subtract that
// many days from the interval to determine the remainder.
var days = Math.floor(interval / msecPerDay );
interval = interval - (days * msecPerDay );
// Calculate the hours, minutes, and seconds.
var hours = Math.floor(interval / msecPerHour );
interval = interval - (hours * msecPerHour );
var minutes = Math.floor(interval / msecPerMinute );
interval = interval - (minutes * msecPerMinute );
var seconds = Math.floor(interval / 1000 );
// Display the result.
document.write(days + " days, " + hours + " hours, " + minutes + " minutes, " + seconds + " seconds.");
//Output: 164 days, 23 hours, 0 minutes, 0 seconds.
}
only this script uses a date to compare the other and that’s not what I need because my system returns a number x of minutes.
the code worked for what you wanted?
– Italo Rodrigo
my initial value is in seconds so I would have to multiply it by 60 correct ?
– Jasar Orion
Yes, you can make the changes in constants according to your needs. creates a new constant called seconds and recalculates constants
– Italo Rodrigo
thanks I made a slight adaptation but solved ^^
– Jasar Orion