/    Sign up×
Community /Pin to ProfileBookmark

clocks and nanoseconds

I am very new to scripting, I have only aptana to check if what i am writing is correct I am adapting a script I found on the net. I have got it doing milliseconds, but what stumped me is that when i tried nanoseconds it didn’t want to know. I’m sure theres a genius out there that could point me in the right direction.
<script language=”JavaScript”>

var clockID = 0;

function UpdateClock() {
if(clockID) {
clearTimeout(clockID);
clockID = 0;
}

var tDate = new Date();

document.theClock.theTime.value = “”
+ tDate.getHours() + “:”
+ tDate.getMinutes() + “:”
+ tDate.getSeconds() + “:”
+tDate.getMilliseconds();

clockID = setTimeout(“UpdateClock()”, 1);
}
function StartClock() {
clockID = setTimeout(“UpdateClock()”, 1);
}

function KillClock() {
if(clockID) {
clearTimeout(clockID);
clockID = 0;
}
}

//–>

</script>
<body onload=”StartClock()” onunload=”KillClock()”>
<center><form name=”theClock”>
<input type=text name=”theTime” size=12>

how do i do nano’s ? as i said this is not my original work aside from one line, eg milliseconds…
Thank you! i have to go back to college in a week and a half and i’d love to getting nano’s by then! is there a way its done by arithmetic if theres not a nano command.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@felgallApr 05.2007 — One millisecond is the smallest unit of time that you can process with Javascript as all times are stored as the number of milliseconds since 1st january 1970 and no provision is made for fractions of milliseconds.

So to work with nanoseconds you will have to redesign the way that Javascript works which means redesigning the way browsers work and since the time setup is based on that used by the operating system you will need to redesign that too. Shouldn't take you more than a few thousand years to do all that - less if you get a few hundred other people to help. Then you will just have the difficulty of convincing everyone to switch from their current system to your new one.
Copy linkTweet thisAlerts:
@mrhooApr 05.2007 — Date.prototype.getNanoseconds=function(){

return this.getTime()*10e6+ (Math.random()*10e5)}

Don't plan any space missions that depend on this function.

But it is guaranteed to be closer than checking your watch....
Copy linkTweet thisAlerts:
@felgallApr 05.2007 — using getMilliseconds in place of getTime would be more consistant with the other time functions. The result would still only really be accurate to the millisecond since the rest of the number after that is random.
Copy linkTweet thisAlerts:
@cheljamauthorApr 05.2007 — thanx guys, the first answer was highly amusing the second I'm going to try as for space missions ..well Nasa arn't looking for me ..yet.

Random, well ball park will nice..just so long as it looks good! impress the increasingly confused computer tutor I have. much appreciated!!!
×

Success!

Help @cheljam 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.28,
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,
)...