JS time since...

jlknauff

New member
Aug 25, 2008
237
1
0
I Googled this, but can't seem to find what I'm looking for and my JS knowledge is next to nothing.

I want a clock (Years Months Days Hours:Minutes) to display the time elapsed since a given date, live in the visitor's browser.

Can someone point me in the right direction?
 


From what I understand so far, it appears that I need to track the seconds, and every second update that variable, parse it out into Years Months Days Hours: Minutes. Is that correct?
 
Shouldn't this work?

Code:
        <script type="text/javascript">
        
            return DateFormat.getDateTimeSince(new Date(1992,1,6,22,30,00)); 

        </script>

I just get a blank screen w/ no output.
 
OP, you're getting confused between getDateTimeInstance & getDateTimeSince . getDateTimeSince isn't an active javascript format. I don't know where you're getting it from.

You'll have to write the javascript function along with it to be able to parse the date in the format you're willing.

Date Calculation in JS is confusing as fuck. Days can have more than 24 hours. Leap years and whatever the fuck not. There are instances of overcalculation as well.

In order to get the current number of days - you can use something as simple as

[JavaScript] JS Time Elapsed - BH from WF - Pastebin.com

And then in order to parse it in your code or call it in html, you can simply use Math.round() {Rounds it off to the lower} or math.ceil() rounds it off to the higher point) in order to get rid of the decimals.

HTML:
 Echo in HTML - BH from WF - Pastebin.com[/url]

[B]Output[/B]
[quote]7747 is the number of days since Thu Feb 06 1992 22:30:00 GMT+0530 [/quote]

[B]P.S - Apparently you can no longer paste JS code in Wickedfire, it kept giving me an access denied error while typing this reply.[/B]

-----------------------------------------------------------------------------------------


Edit - I think I found where you were getting your code from. Here - [url]http://stackoverflow.com/questions/9860783/caculate-time-elapsed-using-javascript[/url] (Ref - Read reply from the Stackoverflow user Kolink)

Notice how he describes a complete function over at  "function getDateTimeSince(target) { // target should be a Date object" in the huge block of code above the one you pasted? That is what will parse your function. It will not come out of thin air. I was Correct.