K
K
K1tekat2022-02-16 18:31:13
Node.js
K1tekat, 2022-02-16 18:31:13

How to format milliseconds to minutes, hours, days?

How much I searched on the Internet and tried to do it, I could not. I want to make the issuance of a role for a while and this time so that it is not indicated in milliseconds, since this is not convenient.
Help who can.
My code:

client.on('messageCreate', message => {
    let array = message.content.split(" ");
    
    if (array[0] === "!role") {
        let member = message.mentions.members.first() || message.guild.members.cache.get(array[1].replace(/[^\d]/g, ''))

        let role = message.guild.roles.cache.get("ID_роли");
        member.roles.add(role).then((Member) => {
            setTimeout(() => {
                Member.roles.remove(role)
            }, Number(array[2]));
        })
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Korotenko, 2022-02-16
@K1tekat

Google knows everything
https://ru.stackoverflow.com/questions/641955/%D0%...

function millisToMinutesAndSeconds(millis) {
  var minutes = Math.floor(millis / 60000);
  var seconds = ((millis % 60000) / 1000).toFixed(0);
  return minutes + ":" + (seconds < 10 ? '0' : '') + seconds;
}

millisToMinutesAndSeconds(298999); // "4:59"
millisToMinutesAndSeconds(60999);  // "1:01"

A
Alex, 2022-02-16
@Kozack

new Date(298999).toLocaleString('en', {minute: '2-digit', second: '2-digit'}) // 04:58

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question