P
P
Pigeon12352020-08-30 18:35:18
Node.js
Pigeon1235, 2020-08-30 18:35:18

How to format seconds into readable form?

There is time in seconds, but I would like to format them depending on their number, i.e.
for example 45 is "45 seconds", 60 is "1 minute", 3601 is "1 hour 1 second". Maybe there are some modules?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergei Nazarenko, 2020-08-31
@nazares

let timestamp = 1598828005;
var minutes = timestamp / 60;
var hours = minutes / 60;
var days = Math.floor(hours / 24) + ' дней, ' +
           Math.floor(hours % 24) + ' часов, ' +
           Math.floor(minutes % 60) + ' минут, ' +
          Math.floor(timestamp % 60) + ' секунд';
          console.log(days);

18504 days, 22 hours, 53 minutes, 25 seconds

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question