/    Sign up×
Community /Pin to ProfileBookmark

seconds and tick:

here’s some code that works for different time zones. however the “Seconds” don’t show/work as there’s no coding for them.
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”>
<html xmlns=”http://www.w3.org/1999/xhtml“>
<head>
<title>Time Zones</title>
<script language=”Javascript” type=”text/javascript”>
<!– Hide script from old browsers

dayName = new Array (“Sunday”,”Monday”,”Tuesday”,”Wednesday”,”Thursday”,”Friday”,”Saturday”)

function showTheHours(theHour) {
if (theHour == 0) {
return (12)
}
if (theHour < 13) {
return (theHour)
}
return (theHour-12)
}

function showZeroFilled(inValue) {
if (inValue > 9) {
return “:” + inValue
}
return “:0” + inValue
}

function showAmPm(thatTime) {
if (thatTime < 12) {
return (” AM “)
}
return (” PM “)
}

function showTheTime(tzOffset) {
thatTZ = new Date
dateStr = thatTZ.toGMTString()
dateStr = dateStr.substr(0,dateStr.length – 3)
thatTZ.setTime(Date.parse(dateStr))
thatTZ.setHours(thatTZ.getHours() + tzOffset)

return showTheHours(thatTZ.getHours()) + showZeroFilled(thatTZ.getMinutes()) + showAmPm(thatTZ.getHours()) + dayName[thatTZ.getDay()]
}

// End hiding script from old browsers –>
</script>

</head>
<body bgcolor=”#FFFFFF”>

<table width=”345″ border=”0″ cellspacing=”0″
cellpadding=”3″ bgcolor=”#000000″>
<tr>
<td valign=”top”>
<script language=”Javascript” type=”text/javascript”>
<!– Hide script from old browsers
document.write(‘<font face=”Arial, Helvetica, sans-serif” size=”2″>’);
document.write(‘<font color=”#FFFF66″>’);
document.write(“Jerusalem: ” + showTheTime(0))
// End hiding script from old browsers –>
</script>
</td>
<td valign=”top”>
<script language=”Javascript” type=”text/javascript”>
<!– Hide script from old browsers
document.write(‘<font face=”Arial, Helvetica, sans-serif” size=”2″>’);
document.write(‘<font color=”#66CCFF”>’);
document.write(“Ottawa: ” + showTheTime(-5))
// End hiding script from old browsers –>
</script>
</td>
</tr>
</table>

</body>
and here’s a revised script trying to add the seconds. however it doesn’t work.
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”>
<html xmlns=”http://www.w3.org/1999/xhtml“>
<head>
<title>Time Zones</title>
<script language=”Javascript” type=”text/javascript”>
<!– Hide script from old browsers

dayName = new Array (“Sunday”,”Monday”,”Tuesday”,”Wednesday”,”Thursday”,”Friday”,”Saturday”)

function showTheHours(theHour) {
if (theHour == 0) {
return (12)
}
if (theHour < 13) {
return (theHour)
}
return (theHour-12)
}

function showZeroFilled(inValue) {
if (inValue > 9) {
return “:” + inValue
}
return “:0” + inValue
}

function showSeconds(theSeconds){
if (inValue > 9 {
return “:” + theSeconds
{
return “:0” + theSeconds

}

function showAmPm(thatTime) {
if (thatTime < 12) {
return (” AM “)
}
return (” PM “)
}

function showTheTime(tzOffset) {
thatTZ = new Date
dateStr = thatTZ.toGMTString()
dateStr = dateStr.substr(0,dateStr.length – 3)
thatTZ.setTime(Date.parse(dateStr))
thatTZ.setHours(thatTZ.getHours() + tzOffset)
thatTZ.setSeconds(thatTZ.getSeconds() + tzOffset)
return showTheHours(thatTZ.getHours()) + showZeroFilled(thatTZ.getMinutes()) + showZeroFilled(thatTZ.getseconds()) + showAmPm(thatTZ.getHours()) + dayName[thatTZ.getDay()]
}

// End hiding script from old browsers –>
</script>

</head>
<body bgcolor=”#FFFFFF”>

<table width=”345″ border=”0″ cellspacing=”0″
cellpadding=”3″ bgcolor=”#000000″>
<tr>
<td valign=”top”>
<script language=”Javascript” type=”text/javascript”>
<!– Hide script from old browsers
document.write(‘<font face=”Arial, Helvetica, sans-serif” size=”2″>’);
document.write(‘<font color=”#FFFF66″>’);
document.write(“Jerusalem: ” + showTheTime(0))
// End hiding script from old browsers –>
</script>
</td>
<td valign=”top”>
<script language=”Javascript” type=”text/javascript”>
<!– Hide script from old browsers
document.write(‘<font face=”Arial, Helvetica, sans-serif” size=”2″>’);
document.write(‘<font color=”#66CCFF”>’);
document.write(“Ottawa: ” + showTheTime(-5))
// End hiding script from old browsers –>
</script>
</td>
</tr>
</table>

</body>
does anyone know how to fix this so that the “Seconds” show up and tick away.
any help would be appreciated.
Apu.

?

to post a comment
JavaScript

18 Comments(s)

Copy linkTweet thisAlerts:
@steelersfan88Mar 06.2004 — Try:[code=php]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Time Zones</title>
<script language="Javascript" type="text/javascript">

dayName = new Array ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")

function showTheHours(theHour) {
if (theHour == 0) {
return (12)
}
if (theHour < 13) {
return (theHour)
}
return (theHour-12)
}

function showZeroFilled(inValue) {
if (inValue > 9) {
return ":" + inValue
}
return ":0" + inValue
}

function showAmPm(thatTime) {
if (thatTime < 12) {
return (" AM ")
}
return (" PM ")
}

function showSec(sec) {
if(sec < 10) {
sec = "0"+ sec.toString()
}
return sec
}

function showTheTime(tzOffset) {
thatTZ = new Date
dateStr = thatTZ.toGMTString()

dateStr = dateStr.substr(0,dateStr.length - 3)
thatTZ.setTime(Date.parse(dateStr))
thatTZ.setHours(thatTZ.getHours() + tzOffset)

return showTheHours(thatTZ.getHours()) + showZeroFilled(thatTZ.getMinutes()) + showZeroFilled(thatTZ.getSeconds()) + showAmPm(thatTZ.getHours()) + dayName[thatTZ.getDay()]
}

function whenLoad() {
otta.innerHTML = showTheTime(-5)
jeru.innerHTML = showTheTime(0)
setTimeout('whenLoad()',1000)
}

</script>
</head>

<body bgcolor="#FFFFFF" onload="whenLoad()">
<table width="405" border="0" cellspacing="0" cellpadding="3" bgcolor="#000000">
<tr>
<td valign="top" align="center">
<font face="Arial, Helvetica, sans-serif" size="2">
<font color="#FFFF66">
Jerusalem: <span id='jeru'></span>
</td>
<td valign="top" align="center">
<font face="Arial, Helvetica, sans-serif" size="2">
<font color="#66CCFF">
Ottawa: <span id='otta'></span>
</td>
</tr>
</table>
</body>[/code]
Copy linkTweet thisAlerts:
@ApuauthorMar 06.2004 — thanks. it works ..however only in ie. if there's a way to get it to work in n/s also i would be grateful.

Thanks again; i'm half way there.

Apu.?
Copy linkTweet thisAlerts:
@steelersfan88Mar 06.2004 — the only thing I changed from your script was the body onload to display the clocks, rather than when the script is reached in the code.

I also used the.getSeconds way, which I would imagine is supported by netscape. And the setTimeout(...). And i added to span objects, not sure which part is not netscape compatible?
Copy linkTweet thisAlerts:
@ApuauthorMar 07.2004 — i think there's an issue with onload in netscape. do you have any suggestions as to how to get around that. ?

thanks for all lthe time your taking to help me out. i would like to use this in a website. in netscape the way it is now is that the two cities are visible but the time doesn't appear. so i don't know enough about javascript to really do a good job of trouble shooting. the span works o.k. i think. if i repace it with <div> tags the time drops down a line in i/e and no visible change in n/s.

stumped,

Apu.
Copy linkTweet thisAlerts:
@ApuauthorMar 07.2004 — would a SafeAddOnload tag be of any help and a browser detection. i have netscape 7.0. does that make a difference? most of the people coming to the site have n/s 6 or >.

is this site of any use?

http://javascript.about.com/library/scripts/blsafeonload.htm

there's a code for browser detection their.

?
Copy linkTweet thisAlerts:
@steelersfan88Mar 07.2004 — This url: http://tech.irt.org/articles/js058/#4 , states almost halfway down that the onload method is supported by Netscape.

Did your code work before I made changes to it on Netscape?
Copy linkTweet thisAlerts:
@ApuauthorMar 07.2004 — thanks for the info. the code that i had worked but the seconds weren't working. now the seconds work in i/e and in n/s the table with its background color and the names of the cities appear but no time at all ..no hours ..no minutes and no seconds.

i wish i knew more about javascript to troubleshoot it but unfortunately i don't.

so any help would be appreciated. i do appreciate all the help you've given so far.

Apu
Copy linkTweet thisAlerts:
@steelersfan88Mar 07.2004 — and netscape doesn't return any errors, just nothing happens?

If so, try adding and alert to each functionright before the return value. Have this alert the return value, something like this:[code=php]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Time Zones</title>

<script language="Javascript" type="text/javascript">

dayName = new Array ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")

function showTheHours(theHour) {
if (theHour == 0) {
alert(12)
return (12)
}
if (theHour < 13) {
alert(theHour)
return (theHour)
}
alert(theHour-12)
return (theHour-12)
}

function showZeroFilled(inValue) {
if (inValue > 9) {
alert(":" + inValue)
return ":" + inValue
}
alert(":" + inValue)
return ":0" + inValue
}

function showAmPm(thatTime) {
if (thatTime < 12) {
alert(" AM ")
return (" AM ")
}
alert(" PM ")
return (" PM ")
}

function showTheTime(tzOffset) {
thatTZ = new Date
dateStr = thatTZ.toGMTString()

dateStr = dateStr.substr(0,dateStr.length - 3)
thatTZ.setTime(Date.parse(dateStr))
thatTZ.setHours(thatTZ.getHours() + tzOffset)

return showTheHours(thatTZ.getHours()) + showZeroFilled(thatTZ.getMinutes()) + showZeroFilled(thatTZ.getSeconds()) + showAmPm(thatTZ.getHours()) + dayName[thatTZ.getDay()]
}

function whenLoad() {
otta.innerHTML = showTheTime(-5)
jeru.innerHTML = showTheTime(0)
//setTimeout('whenLoad()',1000)
}

</script>

</head>

<body bgcolor="#FFFFFF" onload="whenLoad()">
<table width="405" border="0" cellspacing="0" cellpadding="3" bgcolor="#000000">
<tr>
<td valign="top" align="center">
<font face="Arial, Helvetica, sans-serif" size="2">
<font color="#FFFF66">
Jerusalem: <span id='jeru'></span>
</td>
<td valign="top" align="center">
<font face="Arial, Helvetica, sans-serif" size="2">
<font color="#66CCFF">
Ottawa: <span id='otta'></span>
</td>
</tr>
</table>
</body>[/code]
what do the alerts provide in netscape. It SHOULD (but may not) show the hour, minutes, seconds, and AM/PM (no alert for the day!). Note, with this script, i comment the timeout so you did not receive an alert every second.
Copy linkTweet thisAlerts:
@ApuauthorMar 07.2004 — the same thing happens with the alert.

cities appear ..table black..but no time. ?
Copy linkTweet thisAlerts:
@steelersfan88Mar 07.2004 — did any alerts pop up? and if yes, did they contai nthe right information?
Copy linkTweet thisAlerts:
@ApuauthorMar 08.2004 — no "alerts" pop-up. but in my book javascript for the www it says alerts don't work in n/s 6. not sure if that's been corrected for n/s 7.0 which i'm using

apu
Copy linkTweet thisAlerts:
@steelersfan88Mar 08.2004 — not sure, why don't you start a new thread: Why doesn't this work in Netscape 6.0? And Post your code and say it works in IE but not NS. If they tell you youe double posting, i'll take the heat, give them this link: [URL=http://forums.webdeveloper.com/showthread.php?s=&postid=158244#post158244]link here[/URL]
Copy linkTweet thisAlerts:
@ApuauthorMar 08.2004 — one last throw at the cow. in n/s 7.0 there's a javascript console. its sort of a debugger and it says otta not defined L.53. could that and the jeru be whats stopping the code from running in n/s? btw it doesn't run in n/s 4.x either. had a friend load the script and she got the same thing. cities show up but no time at all. btw the alerts do pop up in ie 6.x but not in n/s 7.0
Copy linkTweet thisAlerts:
@PittimannMar 08.2004 — Hi!

If you just take the last code, steelersfan88 posted (didn't even look at the other stuff) and use this as the last function:

function whenLoad() {


document.getElementById('otta').innerHTML = showTheTime(-5)


document.getElementById('jeru').innerHTML = showTheTime(0)


setTimeout('whenLoad()',1000)

}

Netscape should be satisfied...

Cheers - Pit
Copy linkTweet thisAlerts:
@ApuauthorMar 08.2004 — sorry pit: that doesn't do the trick.

do you have to define the function of "otta" ? i don't know where the script picks up the city name of ottawa from otta and jeru. the javascript console says there's a syntax error with the function whenLoad?? but it should be correct ..right? does the span id tag mess up netscape? it seems to me that i read on some site netscape just can't deal with that tag.

thanks for taking a look Pit.
Copy linkTweet thisAlerts:
@PittimannMar 08.2004 — Hi!

Did you use the code, I told you (steelersfan88's last posted code) and pasted the function I posted into that code? It works like it should.

Maybe you post the code you're currently using to be sure...

Cheers - Pit
Copy linkTweet thisAlerts:
@ApuauthorMar 08.2004 — sweet. thank you very, very much. you know me better than i do. i didn't use the last code.

Thank you to you and steallersfan i now i have a working script and a little better understanding of javascript. it takes a lot of patience when you'r a newbie like me. i plan to spend a few hours a day this week reading up on javascript.

Thanks again to the two of you.

Apu
Copy linkTweet thisAlerts:
@PittimannMar 08.2004 — Hi!

I'm glad it works now! As I was just using the code, steelersfan88 posted before, let the thanks go to him!

Cheers - Pit
×

Success!

Help @Apu 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.25,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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