I am working on a page that pulls data from DB. PHP time()
is captured and saved to the DB alongside user contents.
I want to be about to subtract the capturedTime
from the current time using JavaScript and display how long the post has been made in hr : min : s
and should be live.
HTML:
<div class = 'responses'>
<p class = 'capturedTime' style='display: none;'>123456789</p>
</div>
jQuery:
$(document).on('click', '.responses', function () {
$this = $( this );
timeC = $this.prev('.capturedTime').text();
timeNow = $.now()
timeLapsed = ( timeNow - timeC )/1000;
seconds = timeLapsed/60;
mins = seconds/60;
hrs = mins/24;
if ( timeLapsed !== NaN ){
alert(seconds + '------' + mins + '---' + hrs);
}
});