473,394 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Counter... Not Countdown

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 1096
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)
Jul 23 '05 #2
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
JRS: In article <Xn********************@194.109.133.29>, dated Sun, 2
Jan 2005 10:11:11, seen in news:comp.lang.javascript, Evertjan.
<ex**************@interxnl.net> 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.
Jul 23 '05 #4
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" <mi******@comcast.net> 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
JRS: In article <cr********@news2.newsguy.com>, dated Sun, 2 Jan 2005
13:35:18, seen in news:comp.lang.javascript, Richard <An*******@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.
Jul 23 '05 #6
JRS: In article <Xn********************@194.109.133.29>, dated Mon, 3
Jan 2005 10:27:13, seen in news:comp.lang.javascript, Evertjan.
<ex**************@interxnl.net> 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.
Jul 23 '05 #7
Dr John Stockton wrote on 03 jan 2005 in comp.lang.javascript:
JRS: In article <Xn********************@194.109.133.29>, dated Mon, 3
Jan 2005 10:27:13, seen in news:comp.lang.javascript, Evertjan.
<ex**************@interxnl.net> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Matt Stanley | last post by:
I am using the countdown script developed by Chris Nott on his website(http://www.dithered.com/javascript/countdown/example.html). The script counts down the days, hours, minutes and seconds to a...
3
by: Bonnett | last post by:
I have been creating a generic countdown timer (source code below), counting the seconds, minutes, hours and days till an event, but I have having trouble with it finding out how many hours are...
8
by: Prometheus Research | last post by:
http://newyork.craigslist.org/eng/34043771.html We need a JavaScript component which will auto-submit a form after a set period has elapsed. The component must display a counter that dynamically...
4
by: Christine | last post by:
I've implemented a countdown timer for a tutorial web page that should give the user 45 minutes to complete the test, only to find that the timer is slowly 'losing' time. On average, it actually...
31
by: Stephanie | last post by:
I have a newbie question (couldn't find the answer with google) How to show countdown from 10 to 0 seconds. Stephanie
22
by: Papajo | last post by:
This simple script counts up or down with a button click, now can it be modified so the count won't go below zero?            Thanks, Joe <form> <input type=text name=amount size=4 value=>...
4
by: henrik | last post by:
Hi. Can anyone tell me the python code for a simple countdown from eg. 2.00 minutes. It should be printet out to the screen. When it is finished it should write "Time is up" Hope you can...
0
by: Jorhajnes | last post by:
Hi there. Im very new to making games in flash, although I have used flash for quite some time now in web-based situations so I know my way around. Anyways, I thought it would be fun to try...
5
mageswar005
by: mageswar005 | last post by:
hi, I need a javascript countdown timer to my website, I have already the countdown timer but its have some problem. Note: 1) If i choose the tools/internet option in my browser means , at...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.