Skip to content

Instantly share code, notes, and snippets.

View jonathanarbely's full-sized avatar
🐺
Always looking for challenging and cool projects!

Jonathan Arbely jonathanarbely

🐺
Always looking for challenging and cool projects!
View GitHub Profile
@jonathanarbely
jonathanarbely / difference-between-dates.js
Created January 16, 2020 02:11 — forked from DavidWells/difference-between-dates.js
Get difference between two dates. Number of seconds, minutes, hours and days between two unix timestamps.
var unixTimeBetween = function(d1, d2) {
var today = d2.getTime() / 1000
var diff = Math.abs(d1 - (d2.getTime() / 1000));
var result = diff / (60 * 60 * 24);
console.log('Result: ' + result);
if(result * 24 * 60 * 60 < 60)
console.log('Seconds ago: ' + Math.trunc(result * 24 * 60 * 60));
else if(result * 24 * 60 < 60)