JSFiddle - React, Tailwind, and code Playground
by Afzaal Ahmad Zeeshan
JavaScript
function time_until() {
var Time = Date.parse(document.getElementById("time").value);
var curTime = new Date();
var timeToWrite = "";
var seconds = Math.floor((curTime - Time) / (1000));
if (seconds > 0 && seconds < 60) {// seconds..
timeToWrite = seconds + " seconds ago";
} else if (seconds > 60 && seconds < 3600) {//minutes
timeToWrite = Math.floor(seconds / (60)) + " minutes ago";
} else if (seconds > 3600 && seconds < 86400) {//hours..
timeToWrite = Math.floor(seconds / (60 * 60)) + " hours ago";
} else if (seconds > 86400) {//days..
timeToWrite = Math.floor(seconds / (60 * 60 * 24)) + " days ago";
}
$('#update').html(seconds);
$('#jstime').html(timeToWrite + " <b>Time that was captured!</b>");
}