Counter... Not Countdown

M

Mike

Ok, I was just wondering what the code would be for something that
tells me for example how long my relationship has been going.
Hypothetically lets say my gal and I got together 12/7/04 @ 10:30 AM.
And I wanted a box on my website to tell me exactly how long we have
been together, what would the code be? Thanks for your help.

Mike
 
E

Evertjan.

Mike wrote on 02 jan 2005 in comp.lang.javascript:
Ok, I was just wondering what the code would be for something that
tells me for example how long my relationship has been going.
Hypothetically lets say my gal and I got together 12/7/04 @ 10:30 AM.
And I wanted a box on my website to tell me exactly how long we have
been together, what would the code be? Thanks for your help.


Hypothetically:

<script type='text/javascript'>
start = new Date(2004,12-1,7,10,30)
// 12/7/04 @ 10:30 AM
function newdiff(){
now = new Date()
x = Math.floor((now-start)/1000)
secs = x % 60
t = ' and ' + secs + ' seconds'
x = Math.floor(x/60)
mins = x % 60
t = mins + ' minutes ' + t
x = Math.floor(x/60)
hours = x % 24
t = hours + ' hours, ' + t
x = Math.floor(x/24)
days = x
t = days + ' days, ' + t
document.getElementById('d').innerHTML=
t + '<br>'
setTimeout('newdiff()',1000)
}
</script>

<body onload='newdiff()'>
<div id='d'></div>
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Sun, 2
Jan 2005 10:11:11, seen in Evertjan.
<[email protected]> posted :

I see you are assuming the OP to be an American !
start = new Date(2004,12-1,7,10,30)

or new Date("2004/12/07 10:30") ,

which is IMHO more legible, I believe always accepted, and in the spirit
of ISO and FIPS.
x = Math.floor((now-start)/1000)
secs = x % 60
t = ' and ' + secs + ' seconds'
x = Math.floor(x/60)

Since secs is known, the last line could be x = (x-secs)/60 ;
that's shorter, ought to be (insignificantly) quicker, and should not
give any rounding-error problems.
 
R

Richard

Mike said:
Ok, I was just wondering what the code would be for something that
tells me for example how long my relationship has been going.
Hypothetically lets say my gal and I got together 12/7/04 @ 10:30 AM.
And I wanted a box on my website to tell me exactly how long we have
been together, what would the code be? Thanks for your help.

Current time minus the start time of the relationship.

http://www.javascriptkit.com/script/script2/countup.shtml
 
E

Evertjan.

Dr John Stockton wrote on 02 jan 2005 in comp.lang.javascript:
I see you are assuming the OP to be an American !

Yes, three reasons:

1
OP's IP 67.184.110.78 is
c-67-184-110-78.client.comcast.net of comcast in in NJ, USA

2
"Mike" <[email protected]> points to USA

3
12/07/2004 as 7 December is more recent than as 12 July
and fresh love is more demanding, even for code like in the OQ.
or new Date("2004/12/07 10:30") ,

which is IMHO more legible, I believe always accepted,
and in the spirit of ISO and FIPS.

I did not want to introduce the old argument of datestrings here.

In fact more correct [.5 sec max] would be:

x = Math.round((now-start)/1000)

But since the start time is probably not recorded with enough accuracy ..
Since secs is known, the last line could be x = (x-secs)/60 ;
that's shorter, ought to be (insignificantly) quicker, and should not
give any rounding-error problems.

Yes, same quality.
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Mon, 3
Jan 2005 10:27:13, seen in Evertjan.
I did not want to introduce the old argument of datestrings here.


My belief is that I've asserted the safety of the above string form
often enough that, if it were not safe, someone would by now have said
so. And there's benefit in displaying the use of the logical order.

ISTM that the undesirability of using in such a string DD/MM/YYYY and
MM/DD/YYYY is unarguably sound; even if javascript always takes it as
the latter, any person outside the USA is liable to misinterpret it.
 
E

Evertjan.

Dr John Stockton wrote on 03 jan 2005 in comp.lang.javascript:
JRS: In article <[email protected]>, dated Mon, 3
Jan 2005 10:27:13, seen in Evertjan.



My belief is that I've asserted the safety of the above string form
often enough that, if it were not safe, someone would by now have said
so. And there's benefit in displaying the use of the logical order.

ISTM that the undesirability of using in such a string DD/MM/YYYY and
MM/DD/YYYY is unarguably sound; even if javascript always takes it as
the latter, any person outside the USA is liable to misinterpret it.

John, I fully agree with your point of view on yyyymmdd.

I just didn't want to introduce any argument on that, since the OQ was
about date difference, and I did not want to shigt the focus.

I failed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top