adding if statement to function
This one must seem simple for most of you, but its not for me so any help
would be appreciated. How do I add if statements to my function to do this
if ms is > than 86400000 return clock : days + " " + hours if its > than
3600000 return clock : hours + ":" + minutes. Here is what I have so far.
if ( DateDiff ("ms", now, TestDue) >= 0 ) {
var Date1 = new Date();
var Date2 = Date.parse(Date1);
var TestLate1 = Date.parse(TestLate);
var TestDue1 = Date.parse(TestDue);
var TestLate2 = convertMS(TestLate1 - Date2).clock;
var TestDue2 = convertMS(TestDue1 - Date2).clock;
var TestDiff = convertMS(TestLate1 - TestDue1).clock;
tto = "../Images/Blue-120-Button.png";
ttt = "Test Start " + TestDue2;
ttm = "../Images/Blue-120-ButtonMouseOver.png";
ttd = "Test will start in " + TestDue2
+ ", will be due in " + (TestDiff) + "
after that and will be late on " +
TestLate + ".";
C3color = "#FFFFFF";
C3Mcolor = "#FFFF00";
ASTRIS = "../Images/BlueTestB.png";
ASTRIS2 = "../Images/BlueTestB2.png";
so that's the part of the function I need to implement different times for.
function convertMS(ms) {
days = Math.floor(ms / 86400000), // 1 Day = 86400000 Milliseconds
hours = Math.floor((ms % 86400000)/ 3600000), // 1 Hour = 3600000
Milliseconds
minutes = Math.floor((ms % 3600000) / 60000), // 1 Minutes = 60000
Milliseconds
seconds = Math.floor(((ms % 360000) % 60000) / 1000) // 1 Second = 1000
Milliseconds
if (minutes.toString().length == 1 ) {minutes = "0" + minutes};
if (seconds.toString().length == 1 ) {seconds = "0" + seconds};
return {
days : days,
hours : hours,
minutes : minutes,
seconds : seconds,
clock : days + " " + hours + ":" + minutes + ":" + seconds
};
}
No comments:
Post a Comment