Converting seconds into days, hours, minutes and seconds Last Updated : 20 Feb, 2023 Comments Improve Suggest changes Like Article Like Report Given an integer n(in seconds).Convert it into days, hours, minutes and seconds.Examples: Input : 369121517Output : 4272 days 5 hours 45 minutes 17 secondsInput : 129600Output : 1 days 12 hours 0 minutes 0 seconds Number of days = ? n / (24 * 3600) ? Number of Hours = ? (n % (24 * 3600)) / 3600 ? Number of Minutes = ? (n % (24 * 3600 * 3600)) / 60 ? Number of Seconds = ? (n % (24 * 3600 * 3600 * 60)) / 60 ? C++ // C++ program to convert seconds // into days, hours,minutes,seconds #include <bits/stdc++.h> using namespace std; // function convert second into day // hours, minutes and seconds void ConvertSectoDay(int n) { int day = n / (24 * 3600); n = n % (24 * 3600); int hour = n / 3600; n %= 3600; int minutes = n / 60 ; n %= 60; int seconds = n; cout << day << " " << "days " << hour << " " << "hours " << minutes << " " << "minutes " << seconds << " " << "seconds " << endl; } // Driver code int main() { // Given n is in seconds int n = 129600; ConvertSectoDay(n); return 0; } Java // Java program to convert seconds // into days, hours,minutes,seconds import java.io.*; class GFG { // function convert second into day // hours, minutes and seconds static void ConvertSectoDay(int n) { int day = n / (24 * 3600); n = n % (24 * 3600); int hour = n / 3600; n %= 3600; int minutes = n / 60 ; n %= 60; int seconds = n; System.out.println( day + " " + "days " + hour + " " + "hours " + minutes + " " + "minutes " + seconds + " " + "seconds "); } // Driver code public static void main (String[] args) { // Given n is in seconds int n = 129600; ConvertSectoDay(n); } } // This code is contributed by vt_m. Python3 # Python3 program to convert seconds # into days, hours, minutes, seconds # Function convert second into day # hours, minutes and seconds def ConvertSectoDay(n): day = n // (24 * 3600) n = n % (24 * 3600) hour = n // 3600 n %= 3600 minutes = n // 60 n %= 60 seconds = n print(day,"days", hour, "hours", minutes, "minutes", seconds, "seconds") # Driver code # Given n is in seconds n = 129600 ConvertSectoDay(n) # This code is contributed by Anant Agarwal. C# // C# program to convert seconds // into days, hours,minutes,seconds using System; class GFG { // function convert second into day // hours, minutes and seconds static void ConvertSectoDay(int n) { int day = n / (24 * 3600); n = n % (24 * 3600); int hour = n / 3600; n %= 3600; int minutes = n / 60 ; n %= 60; int seconds = n; Console.WriteLine( day + " " + "days " + hour + " " + "hours " + minutes + " " + "minutes " + seconds + " " + "seconds "); } // Driver code public static void Main () { // Given n is in seconds int n = 129600; ConvertSectoDay(n); } } // This code is contributed by vt_m. PHP <?php // PHP program to convert seconds // into days, hours,minutes,seconds // function convert second into day // hours, minutes and seconds function ConvertSectoDay($n) { $day = floor($n / (24 * 3600)); $n = ($n % (24 * 3600)); $hour = $n / 3600; $n %= 3600; $minutes = $n / 60 ; $n %= 60; $seconds = $n; echo ("$day days $hour hours $minutes minutes $seconds seconds"); } // Driver code { // Given n is in seconds $n = 129600; ConvertSectoDay($n); return 0; } // This code is contributed by Nitin Mittal. ?> JavaScript <script> // JavaScript program to convert seconds // into days, hours,minutes,seconds // Function convert second into day // hours, minutes and seconds function ConvertSectoDay(n) { var day =parseInt( n / (24 * 3600)); n = n % (24 * 3600); var hour = parseInt(n / 3600); n %= 3600; var minutes = n / 60; n %= 60; var seconds = n; document.write( day + " " + "days " + hour + " " + "hours " + minutes.toFixed() + " " + "minutes " + seconds.toFixed() + " " + "seconds "); } // Driver code // Given n is in seconds var n = 129600; ConvertSectoDay(n); // This code contributed by Rajput-Ji </script> Output1 days 12 hours 0 minutes 0 seconds Time Complexity: O(1)Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article PHP | Converting string to Date and DateTime M mansibansal2112 Follow Improve Article Tags : Misc Mathematical DSA Basic Coding Problems date-time-program +1 More Practice Tags : MathematicalMisc Similar Reads Program to Convert Milliseconds to a Date Format in Java Given milliseconds. The task is to write a program in Java to convert Milliseconds to a Date that Displays the date in dd MMM yyyy HH:mm:ss:SSS Z format.The Date class in Java internally stores Date in milliseconds. So any date is the number of milliseconds passed since January 1, 1970, 00:00:00 GMT 2 min read Program to Convert Milliseconds to a Date Format in Java Given milliseconds. The task is to write a program in Java to convert Milliseconds to a Date that Displays the date in dd MMM yyyy HH:mm:ss:SSS Z format.The Date class in Java internally stores Date in milliseconds. So any date is the number of milliseconds passed since January 1, 1970, 00:00:00 GMT 2 min read Program to Convert Milliseconds to a Date Format in Java Given milliseconds. The task is to write a program in Java to convert Milliseconds to a Date that Displays the date in dd MMM yyyy HH:mm:ss:SSS Z format.The Date class in Java internally stores Date in milliseconds. So any date is the number of milliseconds passed since January 1, 1970, 00:00:00 GMT 2 min read PHP | Converting string to Date and DateTime Converting the string to Date and DateTime uses several functions/methods like strtotime(), getDate(). We will see what these functions do. strtotime() This is basically a function which returns the number of seconds passed since Jan 1, 1970, just like a linux machine timestamp. It returns the numbe 2 min read PHP | Converting string to Date and DateTime Converting the string to Date and DateTime uses several functions/methods like strtotime(), getDate(). We will see what these functions do. strtotime() This is basically a function which returns the number of seconds passed since Jan 1, 1970, just like a linux machine timestamp. It returns the numbe 2 min read PHP | Converting string to Date and DateTime Converting the string to Date and DateTime uses several functions/methods like strtotime(), getDate(). We will see what these functions do. strtotime() This is basically a function which returns the number of seconds passed since Jan 1, 1970, just like a linux machine timestamp. It returns the numbe 2 min read Like