Question

I have a page that updates whenever another entry is added to the database. It displays the timestamp, and then starts counting up using jQuery, along with moment.js to help with time formatting. This is the code for that:

$(function () {
    var austDay = new Date('".$array['dateAdded']."');
        $('#since".$array['id']."').countdown({since: austDay, significant: 1, layout:  '{d<}{dn} {dl} {d>}{h<}{hn} {hl} {h>}{m<}{mn} {ml} {m>}{s<}{sn} {sl}{s>}'});
});

I need to be able to fire an alert whenever a given entry is 10 minutes past the timestamp date and time. I assume the script would need to continually check to see if that's the case. Any help would be greatly appreciated.

Était-ce utile?

La solution

This is the solution I came up with for this problem, using a mix of Javascript and PHP.

$now = date("Y-m-d h:i:s");
$plusTen = date("Y-m-d, h:i:s", strtotime("+10 minutes", strtotime($array['dateAdded'])));
$difference = strtotime($plusTen) - strtotime($now);
$difference = round($difference,2) * 1000;

if($difference > 0){
echo '<script type="text/javascript">
setTimeout(function(){staleAlert();}, '.$difference.')
</script>';
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top