Skip to main content
Post Made Community Wiki by animusonStaffMod
Now, it fits on one line.
Source Link
AstroCB
  • 12.4k
  • 13
  • 113
  • 129

What time is it?

document.getElementsByTagName("div")[0].style.marginTop = document.height / 3 + "px";

window.setInterval(function () {
    var time = "";
    var now = new Date();
    var hours = "" + now.getHours() + ":";
    var minutes = "" + now.getMinutes() + ":";
    var seconds = "" + now.getSeconds();
    var part;

    if (parseInt(hours) < 12) {
        part = " AM";
    } else {
        hours = parseInt(hours);
        if (hours !== 12) {
            hours -= 12;
        }
        hours += ":";
        part = " PM";
    }
    if (hours.length < 3) {
        hours = "0" + hours;
    }
    if (minutes.length < 3) {
        minutes = "0" + minutes;
    }
    if (seconds.length < 2) {
        seconds = "0" + seconds;
    }
    time += hours;
    time += minutes;
    time += seconds;
    time += part;
    document.getElementById("holder").innerHTML = time;
}, 1000);
div {
    text-align: center;
    font-size: 100pt;70pt;
}
<div id="holder"></div>

What time is it?

document.getElementsByTagName("div")[0].style.marginTop = document.height / 3 + "px";

window.setInterval(function () {
    var time = "";
    var now = new Date();
    var hours = "" + now.getHours() + ":";
    var minutes = "" + now.getMinutes() + ":";
    var seconds = "" + now.getSeconds();
    var part;

    if (parseInt(hours) < 12) {
        part = " AM";
    } else {
        hours = parseInt(hours);
        if (hours !== 12) {
            hours -= 12;
        }
        hours += ":";
        part = " PM";
    }
    if (hours.length < 3) {
        hours = "0" + hours;
    }
    if (minutes.length < 3) {
        minutes = "0" + minutes;
    }
    if (seconds.length < 2) {
        seconds = "0" + seconds;
    }
    time += hours;
    time += minutes;
    time += seconds;
    time += part;
    document.getElementById("holder").innerHTML = time;
}, 1000);
div {
    text-align: center;
    font-size: 100pt;
}
<div id="holder"></div>

What time is it?

document.getElementsByTagName("div")[0].style.marginTop = document.height / 3 + "px";

window.setInterval(function () {
    var time = "";
    var now = new Date();
    var hours = "" + now.getHours() + ":";
    var minutes = "" + now.getMinutes() + ":";
    var seconds = "" + now.getSeconds();
    var part;

    if (parseInt(hours) < 12) {
        part = " AM";
    } else {
        hours = parseInt(hours);
        if (hours !== 12) {
            hours -= 12;
        }
        hours += ":";
        part = " PM";
    }
    if (hours.length < 3) {
        hours = "0" + hours;
    }
    if (minutes.length < 3) {
        minutes = "0" + minutes;
    }
    if (seconds.length < 2) {
        seconds = "0" + seconds;
    }
    time += hours;
    time += minutes;
    time += seconds;
    time += part;
    document.getElementById("holder").innerHTML = time;
}, 1000);
div {
    text-align: center;
    font-size: 70pt;
}
<div id="holder"></div>

Fixed bug, de-jQueryified
Source Link
AstroCB
  • 12.4k
  • 13
  • 113
  • 129

What time is it?

document.getElementsByTagName("div")[0].style.marginTop = $(document).height() / 3 + "px";

window.setInterval(function () {
    var time = "";
    var now = new Date();
    var hours = "" + now.getHours() + ":";
    var minutes = "" + now.getMinutes() + ":";
    var seconds = "" + now.getSeconds();
    var part; 

    if (parseInt(hours) < 12) {
        part = " AM";
    } else if (parseInt(hours) === 12){
        hours = parseInt(hours) + ":";;
        partif =(hours "!== PM";12) {
    } else {      hours -= 12;
        hours}
 = parseInt(hours) - 12 +   hours += ":";
        part = " PM";
    }
    if (hours.length < 3) {
        hours = "0" + hours;
    }
    if (minutes.length < 3) {
        minutes = "0" + minutes;
    }
    if (seconds.length < 2) {
        seconds = "0" + seconds;
    }
    time += hours;
    time += minutes;
    time += seconds;
    time += part;
    $("#holder")document.htmlgetElementById(time"holder");.innerHTML = time;
}, 1000);
div {
    text-align: center;
    font-size: 100pt;
}
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="holder"></div>

What time is it?

document.getElementsByTagName("div")[0].style.marginTop = $(document).height() / 3 + "px";

window.setInterval(function () {
    var time = "";
    var now = new Date();
    var hours = "" + now.getHours() + ":";
    var minutes = "" + now.getMinutes() + ":";
    var seconds = "" + now.getSeconds();
    var part;
    if (parseInt(hours) < 12) {
        part = " AM";
    } else if (parseInt(hours) === 12){
        hours = parseInt(hours) + ":";
        part = " PM";
    } else {
        hours = parseInt(hours) - 12 + ":";
        part = " PM";
    }
    if (hours.length < 3) {
        hours = "0" + hours;
    }
    if (minutes.length < 3) {
        minutes = "0" + minutes;
    }
    if (seconds.length < 2) {
        seconds = "0" + seconds;
    }
    time += hours;
    time += minutes;
    time += seconds;
    time += part;
    $("#holder").html(time);
}, 1000);
div {
    text-align: center;
    font-size: 100pt;
}
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="holder"></div>

What time is it?

document.getElementsByTagName("div")[0].style.marginTop = document.height / 3 + "px";

window.setInterval(function () {
    var time = "";
    var now = new Date();
    var hours = "" + now.getHours() + ":";
    var minutes = "" + now.getMinutes() + ":";
    var seconds = "" + now.getSeconds();
    var part; 

    if (parseInt(hours) < 12) {
        part = " AM";
    } else {
        hours = parseInt(hours);
        if (hours !== 12) {
            hours -= 12;
        }
        hours += ":";
        part = " PM";
    }
    if (hours.length < 3) {
        hours = "0" + hours;
    }
    if (minutes.length < 3) {
        minutes = "0" + minutes;
    }
    if (seconds.length < 2) {
        seconds = "0" + seconds;
    }
    time += hours;
    time += minutes;
    time += seconds;
    time += part;
    document.getElementById("holder").innerHTML = time;
}, 1000);
div {
    text-align: center;
    font-size: 100pt;
}
<div id="holder"></div>

added 116 characters in body
Source Link
AstroCB
  • 12.4k
  • 13
  • 113
  • 129

What time is it?

document.getElementsByTagName("div")[0].style.marginTop = $(document).height() / 3 + "px";

window.setInterval(function () {
    var time = "";
    var now = new Date();
    var hours = "" + now.getHours() + ":";
    var minutes = "" + now.getMinutes() + ":";
    var seconds = "" + now.getSeconds();
    var part;
    if (parseInt(hours) < 12) {
        part = " AM";
    } else if (parseInt(hours) === 12){
        hours = parseInt(hours) + ":";
        part = " PM";
    } else {
        hours = parseInt(hours) - 12 + ":";
        part = " PM";
    }
    if (hours.length < 3) {
        hours = "0" + hours;
    }
    if (minutes.length < 3) {
        minutes = "0" + minutes;
    }
    if (seconds.length < 2) {
        seconds = "0" + seconds;
    }
    time += hours;
    time += minutes;
    time += seconds;
    time += part;
    $("#holder").html(time);
}, 1000);
div {
    text-align: center;
    font-size: 100pt;
}
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="holder"></div>

What time is it?

document.getElementsByTagName("div")[0].style.marginTop = $(document).height() / 3 + "px";

window.setInterval(function () {
    var time = "";
    var now = new Date();
    var hours = "" + now.getHours() + ":";
    var minutes = "" + now.getMinutes() + ":";
    var seconds = "" + now.getSeconds();
    var part;
    if (parseInt(hours) < 12) {
        part = " AM";
    } else {
        hours = parseInt(hours) - 12 + ":";
        part = " PM";
    }
    if (hours.length < 3) {
        hours = "0" + hours;
    }
    if (minutes.length < 3) {
        minutes = "0" + minutes;
    }
    if (seconds.length < 2) {
        seconds = "0" + seconds;
    }
    time += hours;
    time += minutes;
    time += seconds;
    time += part;
    $("#holder").html(time);
}, 1000);
div {
    text-align: center;
    font-size: 100pt;
}
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="holder"></div>

What time is it?

document.getElementsByTagName("div")[0].style.marginTop = $(document).height() / 3 + "px";

window.setInterval(function () {
    var time = "";
    var now = new Date();
    var hours = "" + now.getHours() + ":";
    var minutes = "" + now.getMinutes() + ":";
    var seconds = "" + now.getSeconds();
    var part;
    if (parseInt(hours) < 12) {
        part = " AM";
    } else if (parseInt(hours) === 12){
        hours = parseInt(hours) + ":";
        part = " PM";
    } else {
        hours = parseInt(hours) - 12 + ":";
        part = " PM";
    }
    if (hours.length < 3) {
        hours = "0" + hours;
    }
    if (minutes.length < 3) {
        minutes = "0" + minutes;
    }
    if (seconds.length < 2) {
        seconds = "0" + seconds;
    }
    time += hours;
    time += minutes;
    time += seconds;
    time += part;
    $("#holder").html(time);
}, 1000);
div {
    text-align: center;
    font-size: 100pt;
}
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="holder"></div>

Source Link
AstroCB
  • 12.4k
  • 13
  • 113
  • 129
Loading