Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Counter... Not Countdown

Reply
Thread Tools

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

 
Reply With Quote
 
 
 
 
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>

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


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
 
 
 
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.
<> 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.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<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.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
Reply With Quote
 
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



 
Reply With Quote
 
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" <> 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.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      01-03-2005
JRS: In article <>, 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.

--
© John Stockton, Surrey, UK. ???@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
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.
 
Reply With Quote
 
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.
<> 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 Stockton, Surrey, UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20; Win98. ©
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.
 
Reply With Quote
 
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.
> <> 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.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JSP countdown timer agold791@hotmail.com Java 4 11-03-2005 02:17 AM
countdown log off not sasser or blaster? =?Utf-8?B?am9u?= Windows 64bit 1 10-13-2005 01:45 PM
Countdown thread resume problem bojanraic@gmail.com Java 5 11-30-2004 05:35 PM
Countdown vasilis Java 2 08-23-2004 04:50 PM
GUI countdown timer in a JApplet? Ryan Stewart Java 2 12-24-2003 07:22 PM



Advertisments