Velocity Reviews > Counter... Not Countdown

# Counter... Not Countdown

Mike
Guest
Posts: n/a

 01-02-2005
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

Evertjan.
Guest
Posts: n/a

 01-02-2005
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>

<div id='d'></div>

--
Evertjan.
The Netherlands.

Dr John Stockton
Guest
Posts: n/a

 01-02-2005
JRS: In article <Xns95D271CC23380eejj99@194.109.133.29>, dated Sun, 2
Jan 2005 10:11:11, seen in news:comp.lang.javascript, Evertjan.
<(E-Mail Removed)> 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.

--
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.

Richard
Guest
Posts: n/a

 01-02-2005
Mike wrote:

> 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

Current time minus the start time of the relationship.

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

Evertjan.
Guest
Posts: n/a

 01-03-2005
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" <(E-Mail Removed)> 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.

>> 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.

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

>> x = Math.floor((now-start)/1000)

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 ..

>> 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.

Yes, same quality.

--
Evertjan.
The Netherlands.

Dr John Stockton
Guest
Posts: n/a

 01-03-2005
JRS: In article <(E-Mail Removed)>, dated Sun, 2 Jan 2005
13:35:18, seen in news:comp.lang.javascript, Richard <Anonymous@127.001>
posted :
> Mike wrote:
>
>> 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

>
>Current time minus the start time of the relationship.
>
>http://www.javascriptkit.com/script/.../countup.shtml

It is better to give the code here, if not too long (in this case, the
code *should* be short). It is then much more likely to get checked by
the regulars; remember, much of the code that can be found by Google is
bloated, wrong, or both.

--
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Check boilerplate spelling -- error is a public sign of incompetence.
Never fully trust an article from a poster who gives no full real name.

Dr John Stockton
Guest
Posts: n/a

 01-03-2005
JRS: In article <Xns95D374726C693eejj99@194.109.133.29>, dated Mon, 3
Jan 2005 10:27:13, seen in news:comp.lang.javascript, Evertjan.
<(E-Mail Removed)> posted :
>
>>> 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.

>
>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.

--
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.

Evertjan.
Guest
Posts: n/a

 01-04-2005
Dr John Stockton wrote on 03 jan 2005 in comp.lang.javascript:

> JRS: In article <Xns95D374726C693eejj99@194.109.133.29>, dated Mon, 3
> Jan 2005 10:27:13, seen in news:comp.lang.javascript, Evertjan.
> <(E-Mail Removed)> posted :
>>
>>>> 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.

>>
>>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.
>

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.

--
Evertjan.
The Netherlands.