0

I have an element containing time from event's timestamp. The time is from today. I also have current time with PHP:

$current_time = date('H:i');

It produces the following output: 22:48 but I can convert it to any other format if needed.

I would like to have a simple counter that will show how much time passed since the even took place and the current time and update #timePassed container every minute. The code looks something like this:

<div id="t1">
   Finish: <em>4:05 PM</em> (<span id="timePassed">1 h 25 min</span>)
</div>

I feel that once I figure out how to substract time, I can use jQuery to calculate the time difference and update the container. Something like this:

var time_event = $('#t1 em').text(),
    time_now = '.$current_time.',
    time_pass = time_now - time_event;

setInterval(function () {
    $('#timePassed').text();
}, 60000);

This is just an idea. There's too much still missing...

santa
  • 12,234
  • 49
  • 155
  • 255
  • Possible duplicate of: http://stackoverflow.com/questions/9335140/how-to-countdown-to-a-date – Rasclatt Aug 08 '15 at 04:11
  • You could probably use some of the logic from some of the countdowns on some of the other SO countdown answers. – Rasclatt Aug 08 '15 at 04:12
  • Possibly here as well: http://stackoverflow.com/questions/7344917/javascript-count-up-down-script-to-show-the-time-since-logged-in – Rasclatt Aug 08 '15 at 04:13
  • None of the really help me figure out the time difference between when the even took place and the current time, Once I get that I need to start the increment counter adding to existing difference. – santa Aug 08 '15 at 04:16

0 Answers0