Print Time Of Javascript Using Loop
I stuck until here, I got infinite loop when I proceed. Below code is a half way, how to print from 1:00 AM to 12: AM. http://jsfiddle.net/sychhLya/ JS $(function () { for (i =
Solution 1:
Here is a solution using the Date class in Javascript:
$(function () {
var x = newDate("March 3, 2015 01:00");
for (i = 0; i < 12; i++) {
$('.holder').append(x.getHours() + ":" + x.getMinutes() + x.getSeconds() + "AM<br/>");
x.setHours(x.getHours()+1);
console.log(x);
}
});
JSFiddle: http://jsfiddle.net/sychhLya/3/
Solution 2:
Is this what you want?
$(function() {
for (i = 1; i <= 12; i++) {
var time = '<p>' + i + ':00 AM</p>';
$('.holder').append(time);
}
});
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><pclass="holder"></p>
Or this?
$(function() {
for (i = 1; i <= 12; i++) {
for (j = 0; j < 60; j++) {
j = ("0" + j).slice(-2);
var time = '<p>' + i + ':' + j + ' AM</p>';
$('.holder').append(time);
}
}
});
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><pclass="holder"></p>
Post a Comment for "Print Time Of Javascript Using Loop"