JSFiddle - React, Tailwind, and code Playground

by _sir

HTML

<div id="log"></div>

JavaScript

function getTimeElapsed(timerecorded) {
    if ( typeof timerecorded === 'undefined' ) return null;
    return Math.floor((dateNow - timerecorded) / 1000 / 60);
}

function strToDate(eObj) {
    if ( typeof eObj === 'undefined' ) return null;

    var d = new Date();
    var mEpoch = parseInt(eObj);
    if(mEpoch<10000000000) mEpoch *= 1000;

    d.setTime(mEpoch);
    return d;
}

function doTimeLogic(val) {
    return getTimeElapsed( strToDate(val) );
}

var dateNow = new Date(),
    arr = [
        139462939497,
        "139462939497",
        "",
        "0",
        "Thu Mar 20 2014 09:31:15 GMT-0400"
    ],
    log = document.getElementById("log"),
    i;

for ( i=0; i < 5; i++ ) {
    log.innerHTML += i.toString() + ": " + doTimeLogic( arr[i] ) + "<br>";
}