...

View Full Version : Time counter that is based on another planet



Asteconn
12-12-2006, 03:48 AM
This might sound a little off the hook, but I need a time counter that counts upwards using a different system that that of Earth based days and years. Now - I'm a javascript newbie - I can work with it but I'm utterly clueless when it comes to coding it.

Now - this clock's "years" have to last 35'978'879 seconds, and it's "days" have to last 121'141.007 seconds (exactly).

If it's possible, could counting of the "years" begin at 4898?

If those "days" could be further divided into 12 "hours" and each 120 "minutes" long, that'd be grand - but I'm not expecting miracles.

If you chaps could assist in any way at all that'd be great =] :thumbsup:

Kor
12-12-2006, 09:05 AM
I doubt you can do it with that precision. Un usual PC's clock/counter has a precision around 70 milliseconds ( 2 decimal precision for seconds) while you want a 7 milliseconds precision ( 3 decimal precision for seconds)

Asteconn
12-12-2006, 01:47 PM
I doubt you can do it with that precision. Un usual PC's clock/counter has a precision around 70 milliseconds ( 2 decimal precision for seconds) while you want a 7 milliseconds precision ( 3 decimal precision for seconds)

Ah right. In that case if I ignore the .007?

jalarie
12-12-2006, 03:40 PM
... it's "days" have to last 121'141.007 seconds....
Uh, didn't you mean .006734 instead of .007?
I didn't watch it long enough to make sure it's working properly:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html lang="en-US">
<head>
<title>Clock for Planet X</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Language" content="en-US" />
<meta name="Author" content="James Alarie - jalarie@umich.edu" />

<link rev="made" href="mailto:jalarie@umich.edu" />

<script type="text/javascript">
<!-- Hide this code from non-JavaScript browsers
PX_Start=new Date()*1; // miliseconds since 1970-01-01
PX_SpY=35978879; // seconds per year
PX_SpD=121141.007; // seconds per day
PX_HpD=12; // hours per day
PX_MpH=120; // minutes per hour
PX_SpH=PX_SpD/PX_HpD; // seconds per hour
PX_SpM=PX_SpH/PX_MpH; // seconds per minute
function PlanetX() {
var PX_Time=document.getElementById('PXTime');
var PX_Now=new Date()*1;
var PX_Diff=(PX_Now-PX_Start)/1000; // difference in seconds
var PX_Years=Math.floor(PX_Diff/PX_SpY);
var PX_Year=PX_Years*1+4898;
PX_Diff=PX_Diff-PX_Years*PX_SpY;
var PX_Days=Math.floor(PX_Diff/PX_SpD);
PX_Diff=PX_Diff-PX_Days*PX_SpD;
var PX_Hours=Math.floor(PX_Diff/PX_SpH);
PX_Diff=PX_Diff-PX_Hours*PX_SpH;
var PX_Minutes=Math.floor(PX_Diff/PX_SpM);
var PX_Seconds=PX_Diff-PX_Minutes*PX_SpM;
PX_Seconds=Math.round(PX_Seconds);
if (PX_Hours < 10) { PX_Hours='0'+PX_Hours; }
if (PX_Minutes < 10) { PX_Minutes='0'+PX_Minutes; }
if (PX_Minutes < 100) { PX_Minutes='0'+PX_Minutes; }
if (PX_Seconds < 10) { PX_Seconds='0'+PX_Seconds; }
var PX_Out=PX_Year+' '+PX_Days+' '+PX_Hours+':'+PX_Minutes+':'+PX_Seconds;
PX_Time.innerHTML=PX_Out;
var PX_delay=1000; // delay in milliseconds
var PX_timeout=setTimeout("PlanetX();",PX_delay);
} // PlanetX
// End hiding -->
</script>

</head>

<body background="jaa_bgnd.jpg" bgcolor="#ffffee" text="black"
link="blue" vlink="#800088" alink="red"
onload="PlanetX();">
<!-- Page Header -->
<div class="header">
<div align="center"><h1>Clock for Planet X</h1></div>
<hr />
</div>

<!-- Content -->
<div class="content">
<br />
<noscript>
<font color="red">
You must have javascript to make use of this page.
</font>
</noscript>

<p>
The time is now
<span name="PXTime" id="PXTime">&nbsp;</span>
on Planet X.
</p>

</div>

<!-- Page Footer -->
<div class="footer">
<br clear="all" /><hr />
Written on December 12, 2006, by:&nbsp;
<a href="mailto:jalarie@umich.edu">James Alarie</a>
</div>
</body>
</html>

Asteconn
12-12-2006, 04:18 PM
o_O blimey. Many thanks =D !

How did you go about constructing it? [myself being such a newb etc.] I mean - what were your thought processes?

jalarie
12-12-2006, 04:58 PM
How did you go about constructing it? ... what were your thought processes?
1. Start with a web page template. I have one set up with lots of "standard stuff" in it; I find it faster to delete what I don't want than to add what I do want.
2. I need a place (time) to start, so I pick up the time when the page is loaded with "PX_Start=new Date()*1;".
3. The conversion factors belong outside the funciton, so they are stated next: "PX_SpY=35978879;" up to the "function" line.
4. A function needs to exist to calculate and update the time. I create a base function which does nothing and I'll fill it in later.
5. The function needs to run as soon as the page loads and every so often after that: 'onload="PlanetX();"' and the 'var PX_delay=1000;' and 'var PX_timeout=setTimeout("PlanetX();",PX_delay);' lines.
6. Add the '<span ... </span>' line for a place to put the result.
7. Fill in the function to get the current time, find the difference between now and when the page was initially loaded, divide by the given factor to get years, subtract years from the difference, repeat years type calculation for days, hours, and minutes, and the remainder is the leftover seconds.
8. display the result.

Asteconn
12-13-2006, 02:45 AM
Ah right =] Thanks for that *disects information and pokes about the code*

If I wanted to take a fixed date and time as a starting point, rather than when the page was loaded, how would I do that?

jalarie
12-13-2006, 01:45 PM
If I wanted to take a fixed date and time as a starting point, rather than when the page was loaded, how would I do that?


PX_Start_Year=???;
PX_Start_Month=???-1; // the -1 is because Javascript counts 0-11
PX_Start_Day=???;
PX_Start_Hour=???;
PX_Start_Minute=???;
PX_Start_Second=???;
PX_Start=new Date(PX_Start_Year,PX_Start_Month,PX_Start_Day,PX_Start_Hour,PX_Start_Minute,PX_Start_Second)*1;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum