JS Date Tests
by Marventus
HTML
<div class="wrap">
<input type="button" value="Date" />
<em>Check yout console!</em>
</div>
CSS
input[type="button"] {
display: block;
margin-bottom: 5px;
padding: 5px 10px;
width: 100px;
}
.wrap {
padding: 10px;
}
}
JavaScript
$("input[type='button']").click(function() {
var d = new Date(),
month = d.getMonth()+1,
day = d.getDate(),
hs = d.getHours() <= 12 ? d.getHours() : d.getHours() -12,
min = d.getMinutes(),
ampm = d.getHours() <= 11 ? "am" : "pm",
output = d.getFullYear() + '/' +
((''+month).length<2 ? '0' : '') + month + '/' +
((''+day).length<2 ? '0' : '') + day +
' at ' + hs + ":" + min + ampm
;
console.log(output);
});