Reputation: 165
I've created a javascript to show date&time in Javascript, but it doesn't return anything I've tried a lot of advises, but nothing worked.
HTML CODE
function startTime() {
var today = new Date();
var hr = today.getHours();
var min = today.getMinutes();
var sec = today.getSeconds();
ap = (hr < 12) ? "<span>AM</span>" : "<span>PM</span>";
hr = (hr == 0) ? 12 : hr;
hr = (hr > 12) ? hr - 12 : hr;
//Add a zero in front of numbers<10
hr = checkTime(hr);
min = checkTime(min);
sec = checkTime(sec);
document.getElementById("clock").innerHTML = hr + ":" + min + ":" + sec + " " + ap;
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
var curWeekDay = days[today.getDay()];
var curDay = today.getDate();
var curMonth = months[today.getMonth()];
var curYear = today.getFullYear();
var date = curWeekDay+", "+curDay+" "+curMonth+" "+curYear;
document.getElementById("date").innerHTML = date;
var time = setTimeout(function(){ startTime() }, 500);
}
function checkTime(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
div {
margin
border-radius:15px;
color:#ecf0f1;
text-align:center;
font-size:70px
}
<div id="clock"></div>
<div id="date"></div>
Could I change this javascript code to show time from 5 different timezones?
Upvotes: 2
Views: 65
Reputation: 165
Ah, I forgot about calling. Sorry.
Worked with
window.onload = function () {
'use strict';
setInterval(startTime, 500);
Upvotes: 1
Reputation: 1402
in order it works, it's important to call function startTime, so add this line to your javasrcipt code.
startTime();
Upvotes: 0