PROBLEM 7
Easy

Seconds to Time

Programming Basics · JavaScript

</>
STATUS Not solved

TASK

Problem

#7

Given seconds `s` from the start of a day, print hours, minutes, and seconds separated by spaces.

EXAMPLE

Example

Input
3665
Output
1 1 5

LIMITS

Constraints

0 ≤ s < 86,400
📖
LEARN Theory for this problem
+

### Seconds to Time

Integer division separates higher decimal/time units, while `%` returns the remainder. These two operations let a program isolate digits or split a total number of seconds/minutes into components.

💡
NEED HELP? Hints
+

['Decide which part comes from division and which part comes from the remainder.', 'Match each input value type to the operation performed on it: JavaScript string and numeric behavior differ significantly.']

ANSWER Solution
+
const fs = require('fs');

const totalSeconds = Number(fs.readFileSync(0, 'utf8').trim());

const hours = Math.floor(totalSeconds / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60);
const seconds = totalSeconds % 60;

console.log(hours, minutes, seconds);