/    Sign up×
Community /Pin to ProfileBookmark

Date/Time script, converting from PHP

Hello,

I recently created a [URL=”http://hpnpilot1200.org/clock/date.php”]page using php[/URL] to indicate the date (EST) and time in multiple time zones. In PHP, the only way to update these items would be to refresh the entire page every second or so, which is obviously a nuisance (even with a line or two of javascript). Ultimately, I would like the date and times to automatically update every second without the entire page physically refreshing.

So…I attempted to convert the page into javascript instead, but I’m having some difficulties. I found a few javascripts on the ‘net to accomplish the time updating, but it’s not exactly working.

This is the javascript I was working off of:

[code=php]<span id=”dt”></span>
<script type=”text/javascript”>

var currentTime = new Date()
var hours = currentTime.getUTCHours()
var minutes = currentTime.getUTCMinutes()
if (minutes < 10)
minutes = “0” + minutes
var seconds = currentTime.getUTCSeconds()
if (seconds < 10)
seconds = “0” + seconds
var UTCTime = hours + “:” + minutes + “:” + seconds;

setInterval(‘dispUTCtime()’, 1000);

function dispUTCtime() {
document.getElementById(‘dt’).innerHTML = UTCTime;
}[/code]

Using that code, the time appears, but the seconds/minutes/hours do not update per the setInterval. I also need to create additional scripts of the same type for different time zones. Any help is greatly appreciated and I look forward to working on this script.

Regards,
Jason H.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@forty2Jan 27.2007 — <i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;New Document&lt;/title&gt;
&lt;script type="text/javascript"&gt;
var obj = null;

<i> </i> function GrinuichTime()
<i> </i> {
<i> </i> var curently = new Date();
<i> </i> var hours = toFix(curently.getUTCHours());
<i> </i> var minutes = toFix(curently.getMinutes());
<i> </i> var seconds = toFix(curently.getSeconds());

<i> </i> obj.innerHTML = hours +':'+ minutes +':'+ seconds;
<i> </i> setTimeout('GrinuichTime()', 1000);
<i> </i> }

<i> </i> function toFix(sender)
<i> </i> {
<i> </i> return (sender &lt; 10) ? '0'+sender : sender;
<i> </i> }

<i> </i> window.onload = function ()
<i> </i> {
<i> </i> obj = document.getElementById('clock');
<i> </i> GrinuichTime();
<i> </i> }
<i> </i> &lt;/script&gt;
<i> </i>&lt;/head&gt;
<i> </i>&lt;body&gt;
<i> </i> &lt;span id="clock"&gt;&lt;/span&gt;
<i> </i>&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@hpnpilot1200authorJan 28.2007 — Thanks forty2!

What would be the best way to manipulate the code to allow for additional time zones to be displayed and updated every 1000 milliseconds?

Thanks,

Jason
×

Success!

Help @hpnpilot1200 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 6.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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