Hello everyone
in sum ..
I want to show the time remaining in the status page
So i add the code: $(session-time-left) on it
Everything is fine
the time remaining shows like this: 5w3d9h4m
So in fact this means that remaining 5 weeks and 3 days, 9 hours and 4 minutes
All I want is to replace this: 5w3d9h4m
to this: 5 weeks and 3 days, 9 hours and 4 minutes
I think that it is very easy
Sorry I’m Newbie, And Sorry for my bad English
where are you people!!!???
You’d need to parse this with JavaScript.
I think it will be easiest with string.split, like:
<div id="timeLeft">$(session-time-left)</div>
<script type="text/javascript">
var timeLeft = "$(session-time-left)".split(/\d+/);
for (var i =0, l = timeLeft.length; i<l; ++i) {
switch(timeLeft[i]) {
case "w":
timeLeft[i] = " weeks, ";
break;
case "d":
timeLeft[i] = " days, ";
break;
case "h":
timeLeft[i] = " hours, ";
break;
case "m":
timeLeft[i] = " minutes";
break;
}
}
document.getElementById("timeLeft").innerHTML = timeLeft.join();
</script>
boen_robot:
You’d need to parse this with JavaScript.
I think it will be easiest with string.split, like:
<div id="timeLeft">$(session-time-left)</div>
<script type="text/javascript">
var timeLeft = "$(session-time-left)".split(/\d+/);
for (var i =0, l = timeLeft.length; i<l; ++i) {
switch(timeLeft[i]) {
case "w":
timeLeft[i] = " weeks, ";
break;
case "d":
timeLeft[i] = " days, ";
break;
case "h":
timeLeft[i] = " hours, ";
break;
case "m":
timeLeft[i] = " minutes";
break;
}
}
document.getElementById("timeLeft").innerHTML = timeLeft.join();
</script>
thank u 4 reply
but nothing changed after i add the script
I tested the script, and although it didn’t produced the expected results, it did make a difference… maybe JavaScript wasn’t enabled in your browser when you tested?
Anyway, here’s a simpler script that produces the correct results:
<div id="timeLeft">$(session-time-left)</div>
<script type="text/javascript">
document.getElementById("timeLeft").innerHTML = "$(session-time-left)".replace("w", " weeks, ").replace("d", " days, ").replace("h", " hours and ").replace("m", " minutes.");
</script>
navyday
September 5, 2015, 10:33am
7
SubZero:
boen_robot:
I tested the script, and although it didn’t produced the expected results, it did make a difference… maybe JavaScript wasn’t enabled in your browser when you tested?
Anyway, here’s a simpler script that produces the correct results:
<div id="timeLeft">$(session-time-left)</div>
<script type="text/javascript">
document.getElementById("timeLeft").innerHTML = "$(session-time-left)".replace("w", " weeks, ").replace("d", " days, ").replace("h", " hours and ").replace("m", " minutes.");
</script>
now it works
thank u very much bro
how to replace this code and that would put
Sorry I’m Newbie, And Sorry for my bad English