js时间戳转化成天、时、分、秒

function convertTimestamp(timestamp) {
    const seconds = Math.floor(timestamp / 1000);
    const days = Math.floor(seconds / (3600 * 24));
    const hours = Math.floor((seconds % (3600 * 24)) / 3600);
    const minutes = Math.floor((seconds % 3600) / 60);
    const remainingSeconds = seconds % 60;

    return {
        days: days,
        hours: hours,
        minutes: minutes,
        seconds: remainingSeconds
    };
}

const timestamp = 7000; // 示例小时间戳
const convertedTime = convertTimestamp(timestamp);
console.log(convertedTime);
{
    days: 0,
    hours: 0,
    minutes: 1,
    seconds: 10
}

你可能感兴趣的:(javascript,前端,开发语言)