PDA

View Full Version : Javascript Help Needed



ssc456
Mar 9th, 2008, 07:32 PM
right first of all, hi guys im new to javascript i have done a fair amount of html but so far have avoided javascript,

i need a script that will do the following and quiet simply have no idea where to start so.

the script needs to start by getting the current time,

in hours, miniutes, and seconds ........ obviously

then i need it to do the following formular,

(hoursX60+miniutes)X60+secondsX1.1574

and then display the result.

if any1 could be of help i would be very greatful, as i say in javascrip i am a complete novice so a full code from beginning to end would be very helpful,

many thanks scott

PeaTearGriffin
Mar 9th, 2008, 08:00 PM
You can try this:

<script type="text/javascript">
var myDate = new Date();
hrs = myDate.getHours();
mins = myDate.getMinutes();
secs = myDate.getSeconds();

document.write((hrs*60+mins) * 60 + secs * 1.1574)
</script>

Philip M
Mar 9th, 2008, 08:26 PM
document.write((hrs*60+mins) * 60 + secs * 1.1574)

This multiplies secs (only) by 1.1574 and adds to the previous result.

It is the equivalent of:
document.write((hrs*60+mins) * 60 + (secs * 1.1574))

Presumably what is wanted is

document.write((hrs*60+mins) * (60 + secs) * 1.1574)

ssc456
Mar 9th, 2008, 08:41 PM
document.write((hrs*60+mins) * 60 + secs * 1.1574)

This multiplies secs (only) by 1.1574 and adds to the previous result.

It is the equivalent of:
document.write((hrs*60+mins) * 60 + (secs * 1.1574))

Presumably what is wanted is

document.write((hrs*60+mins) * (60 + secs) * 1.1574)

thats not what i needed,

what i need is the time as of now in seconds.

which would be as of 19:40 id work that out as 19 hours * 60 to get mins which would be 1140 + the current 40 mins, 1180 mins then * 60 to get seconds 68400 seconds plus the current seconds then * by 1.1574,

and for some reason im not getting the right result.

edit: just figured i think i need to declare a new variable which is the sum of (hrs*60) + mins, ..... that would be the full time today in mins,

say a variable of todaymins = (hrs*60) + mins
then a new variable of todaysecs = (todaymins*60) + secs

document.write(todaysec*1.1574)

also while were here could be add in so it updates every 0.864 seconds.

( i may not no javascript but i no maths :) )

Philip M
Mar 10th, 2008, 08:46 AM
( i may not no javascript but i no maths :) )

No! Really?


<body onload = "getSeconds()">

<script type="text/javascript">

function getSeconds() {
var myDate = new Date();
hrs = myDate.getHours();
mins = myDate.getMinutes();
secs = myDate.getSeconds();
document.myForm.showSecs.value = (((hrs*3600) + (mins * 60) + secs) * 1.1574); // curent time in seconds x 1.1574
window.setTimeout("getSeconds()", 864); // refresh every 864 milliseconds
}

</script>

<form name = "myForm">
<input type = "text" name = "showSecs" size "12">
</form>


Quizmaster: Of which country did Ben Gurion become Prime Minister in 1948?
Contestant: Wales.

ssc456
Mar 10th, 2008, 07:18 PM
No! Really?


<body onload = "getSeconds()">

<script type="text/javascript">

function getSeconds() {
var myDate = new Date();
hrs = myDate.getHours();
mins = myDate.getMinutes();
secs = myDate.getSeconds();
document.myForm.showSecs.value = (((hrs*3600) + (mins * 60) + secs) * 1.1574); // curent time in seconds x 1.1574
window.setTimeout("getSeconds()", 864); // refresh every 864 milliseconds
}

</script>

<form name = "myForm">
<input type = "text" name = "showSecs" size "12">
</form>


Quizmaster: Of which country did Ben Gurion become Prime Minister in 1948?
Contestant: Wales.


lol just as i was finishing work today i figured that out, but thanks so much for all your help guys.