459,253 Members | 1,676 Online
Need help? Post your question and get tips & solutions from a community of 459,253 IT Pros & Developers. It's quick & easy.

# Counter... Not Countdown

 P: n/a 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 Jul 23 '05 #1
7 Replies

 P: n/a 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:
-- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress) Jul 23 '05 #2

 P: n/a 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 Jul 23 '05 #3

 P: n/a JRS: In article , 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 © JL/RC: FAQ of news:comp.lang.javascript jscr maths, dates, sources. TP/BP/Delphi/jscr/&c, FAQ items, links. Jul 23 '05 #4

 P: n/a 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) Jul 23 '05 #5

 P: n/a JRS: In article , dated Sun, 2 Jan 2005 13:35:18, seen in news:comp.lang.javascript, Richard 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. MikeCurrent 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 - 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. Jul 23 '05 #6

 P: n/a JRS: In article , 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 - FAQqish topics, acronyms & links. PAS EXE TXT ZIP via My DOS - also batprogs.htm. Jul 23 '05 #7

 P: n/a Dr John Stockton wrote on 03 jan 2005 in comp.lang.javascript: JRS: In article , 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) Jul 23 '05 #8

### This discussion thread is closed

Replies have been disabled for this discussion.