Forum Moderators: open

Message Too Old, No Replies

Parsing Date and Time Into a Script

         

itledi

11:51 pm on Feb 2, 2008 (gmt 0)

10+ Year Member



Hello,

What I'm trying to do is to somehow parse a date/time stamp that looks like this "2008-02-02 10:28:17", and to create a variable that calculates how long ago that was.

How would I even start with inserting a timestamp into my function.

In my loop statment time[i].innerHTML="2008-02-02 10:28:17";

Can I go like this?
var now=new Date();
var old=new Date();
old.setTime(time[i].innerHTML);
var current=now-old;

Thanks

daveVk

12:24 am on Feb 3, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



elapsed = (now.getTime() - old.getTime() );

gives time difference ms.

[msdn2.microsoft.com...]

[edited by: daveVk at 12:33 am (utc) on Feb. 3, 2008]

itledi

11:57 pm on Feb 3, 2008 (gmt 0)

10+ Year Member



Thank you for your help.

That tid bit helped me a lot! And it moved me to find Date.parse().

I was able to create all of the script, but I have one small bug.

Anyone have an idea how I can strip off the date ending without affecting a month like August?

This will work, except for months with August in them.

time="February 3rd 2008, 9:47".replace(/st¦nd¦rd¦th/,"");

Any ideas would be much appreciated.

daveVk

4:27 am on Feb 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Probably cleaner way, try

time="February 3rd 2008, 9:47".replace(/nd¦rd¦th/,"").replace(/1st/,"1");

itledi

4:12 pm on Feb 4, 2008 (gmt 0)

10+ Year Member



Ahhhh!

What a smart idea, I like it!

So I guess the replaces can be stacked one after each other?

I'll try the code tonight.

Thanks