JSFiddle - React, Tailwind, and code Playground

Clock Block Widget

by Jennifer Perrin

HTML

<script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.1.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.1.0/css/bootstrap.css">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css">
<script src="http://fonts.googleapis.com/css?family=Muli:400,300,300italic,400italic"></script>
<div id="weather-widget-1" class="outer-square setter time">
    <div id="do-time"></div>
</div>

CSS

html, body {
    height: 100%;
    font-family: 'Muli';
}
body {
    background: -webkit-radial-gradient(circle, #8dcded, #0a2c3e);
    background: radial-gradient(circle, #8dcded, #0a2c3e);
    line-height: 1.5;
}
*, *:before, *:after {
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}
.cf:before, .cf:after {
    content:" ";
    display: table;
}
.cf:after {
    clear: both;
}
.cf {
    *zoom: 1;
}
.outer-square {
    position: relative;
    background: #1E8BC3;
    width: 300px;
    overflow: hidden;
    border: 5px solid #fff;
    margin: 30px auto;
}
.outer-square:before {
    content:"";
    display: block;
    padding-top: 100%;
}
.time * {
    text-align: center;
    text-transform: uppercase;
    color: #fff;
}
#do-time {
    width: 100%;
    height: 100%;
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    padding: 1em;
}
.time h2 {
    font-size: 4em;
    font-weight: 300;
    line-height: 1;
    margin-top: .25em;
}
.time h2 span {
    font-weight: 100;
}
.time h3 {
    font-size: 1.5em;
    font-weight: 300;
    line-height: 1;
    margin-top: 2em;
}
.time h3 span {
    display: block;
}
.time small {
    font-size: 1em;
    font-weight: 100;
}

JavaScript

setInterval(function () {
    document.getElementById("do-time").innerHTML = formatTime();
}, 1000);

function formatTime() {
    var d = new Date(),
        minutes = d.getMinutes().toString().length == 1 ? '0' + d.getMinutes() : d.getMinutes(),
        hours = d.getHours().toString().length == 1 ? '0' + d.getHours() : d.getHours(),
        ampm = d.getHours() >= 12 ? 'pm' : 'am',
        months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
        days = ['Sunday', 'Monday', 'Tueday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
    return '<h2>' + hours + '<span>:' + minutes + '</span></h2><small>' + ampm + '</small><h3>' + days[d.getDay()] + '<span>' + months[d.getMonth()] + ' ' + d.getDate() + '</span>' + d.getFullYear() + '</h3>';
}