Answers for "how to convert a timestamp to days in js"

17

unix time to date javascript

const unixTime = 1210981217;
const date = new Date(unixTime*1000);
console.log(date.toLocaleDateString("en-US"));
//expected: "5/16/2008"
Posted by: Guest on May-20-2020
1

javascript get remaining time from start and end datetime

function calculateExamRemainingTime(exam_end_at) {

    $(function(){

        const calcNewYear = setInterval(function(){

            const exam_ending_at    = new Date(exam_end_at);
            const current_time      = new Date();
           
            const totalSeconds     = Math.floor((exam_ending_at - (current_time))/1000);;
            const totalMinutes     = Math.floor(totalSeconds/60);
            const totalHours       = Math.floor(totalMinutes/60);
            const totalDays        = Math.floor(totalHours/24);

            const hours   = totalHours - ( totalDays * 24 );
            const minutes = totalMinutes - ( totalDays * 24 * 60 ) - ( hours * 60 );
            const seconds = totalSeconds - ( totalDays * 24 * 60 * 60 ) - ( hours * 60 * 60 ) - ( minutes * 60 );

            const examRemainingHoursSection = document.querySelector('#remainingHours');
            const examRemainingMinutesSection = document.querySelector('#remainingMinutes');
            const examRemainingSecondsSection = document.querySelector('#remainingSeconds');

            examRemainingHoursSection.innerHTML = hours.toString();
            examRemainingMinutesSection.innerHTML = minutes.toString();
            examRemainingSecondsSection.innerHTML = seconds.toString();

        },1000);
    });
}

calculateExamRemainingTime('2025-06-03 20:20:20');
Posted by: Guest on June-28-2020

Code answers related to "how to convert a timestamp to days in js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language