/    Sign up×
Community /Pin to ProfileBookmark

Time JavaScript Help Needed

I am a true beginner trying to find/write a javascript to display the current time on my webpage that will work on multiple types of web browsers. Below is what I have but it doesn’t work in Firefox or Safari. I am also trying to make it work off a 24 hr clock. Any help would be greatly appreciated

Thanks
~Brian


———

<script language=”Javascript1.2″>

if(navigator.appName == “Netscape”) {
document.write(‘<layer id=”clock”></layer><br>’);
}

if (navigator.appVersion.indexOf(“MSIE”) != -1){
document.write(‘<span id=”clock”></span><br>’);
}

function upclock(){
var dte = new Date();
var hrs = dte.getHours();
var min = dte.getMinutes();
var sec = dte.getSeconds();
var col = “:”;
var spc = ” “;
var apm;

if (12 < hrs) {
apm=”PM”;
hrs-=12;
}

else {
apm=”AM”;
}

if (hrs == 0) hrs=12;
if (min<=9) min=”0″+min;
if (sec<=9) sec=”0″+sec;

if(navigator.appName == “Netscape”) {
document.clock.document.write(hrs+col+mi n+col+sec+spc+apm);
document.clock.document.close();
}

if (navigator.appVersion.indexOf(“MSIE”) != -1){
clock.innerHTML = hrs+col+min+col+sec+spc+apm;
}
}

setInterval(“upclock()”,1000);
//–>
</script>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@CharlesSep 18.2005 — &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;meta name="Content-Script-Type" content="text/javascript"&gt;
&lt;meta name="Content-Style-Type" content="text/css"&gt;
&lt;title&gt;Example&lt;/title&gt;

&lt;script type="text/javascript"&gt;

if (document.getElementById) onload = function () {
p = document.createElement ('P')
document.getElementsByTagName ('BODY')[0].appendChild (p)
time = document.createTextNode (new Date().toTimeString())
p.appendChild (time)
p.setAttribute ('id', 'time')
setInterval ("document.getElementById ('time').firstChild.data = new Date().toTimeString()", 50)
}

&lt;/script&gt;

&lt;style type="text/css"&gt;
#time {text-align:right}
&lt;style&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;/body&gt;
&lt;/html&gt;
×

Success!

Help @tmgolf spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...