Skip to content

Instantly share code, notes, and snippets.

@robozavri
Last active September 10, 2020 08:07
Show Gist options
  • Save robozavri/2414756173cfa846bfc4bae1a2eb08da to your computer and use it in GitHub Desktop.
Save robozavri/2414756173cfa846bfc4bae1a2eb08da to your computer and use it in GitHub Desktop.
#javascript get difference beetwen two dates and set timeout moment.js
var a = moment();//now
var b = moment('2020-04-30T13:28:00');
console.log('now',moment().toDate());
console.log(a.diff(b, 'milisecunds')) // 44700
console.log(a.diff(b, 'seconds')) // 44700
console.log(a.diff(b, 'minutes')) // 44700
console.log(a.diff(b, 'hours')) // 745
console.log(a.diff(b, 'days')) // 31
console.log(a.diff(b, 'weeks')) // 4
setTimeout(()=>{ //<<<--- using ()=> syntax
console.log('wow works now is :',moment().toDate()) // 4
},Math.abs((a.diff(b, 'milisecunds') ) ) );
console.log( Math.abs((a.diff(b, 'milisecunds') ) ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment