Seconds To Time

Run Settings
LanguageC++
Language Version
Run Command
#include <iostream> using namespace std; // Turn seconds into a more readable length of time void secondsToTime(long long durationInSeconds) { // First lets get out seconds unsigned int seconds = durationInSeconds % 60; // Second lets convert the seconds to minutes unsigned long long minutes = durationInSeconds / 60; // Then we can figure out our hours unsigned long long hours = minutes / 60; // We set minutes to the remaineder of minutes left over from converting to hours minutes = minutes % 60; unsigned long long days = hours / 24; hours = hours % 24; // lets get weeks unsigned long long weeks = days / 7; days = days % 7; // Get months unsigned long long months = weeks / 4; weeks = weeks % 4; unsigned long long years = months / 12; months = months % 12; cout << years << " year(s) " << months << " month(s) " << weeks << " week(s) " << days << " day(s) " << " " << hours << ":" << minutes << ":" << seconds << "\n"; } int main() { // (100000000000); secondsToTime(4847348848383700000); secondsToTime(9999999999999999999); return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines