• Simple JavaScript seconds counter

    November 19, 2019

    /** * @author Ivan Gospodinow * @site http://ivangospodinow.com/?p=471 * * @param {callback} onUpdate * @return {callback} onStop */ export function countSeconds(onUpdate) { const start = new Date(); const interval = setInterval(() => { onUpdate(parseInt((new Date().getTime() – start.getTime()) / 1000)); }, 1000); return () => { clearInterval(interval); }; }   Usage: /** let seconds = 0; […]

 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org