Given an integer n(in seconds).Convert it into days, hours, minutes and seconds.
Examples:
Input : 369121517
Output : 4272 days 5 hours 45 minutes 17 seconds
Input : 129600
Output : 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++
#include <bits/stdc++.h>
using namespace std;
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;
}
int main()
{
int n = 129600;
ConvertSectoDay(n);
return 0;
}
|
Java
import java.io.*;
class GFG
{
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 " );
}
public static void main (String[] args)
{
int n = 129600 ;
ConvertSectoDay(n);
}
}
|
Python3
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" )
n = 129600
ConvertSectoDay(n)
|
C#
using System;
class GFG {
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 " );
}
public static void Main ()
{
int n = 129600;
ConvertSectoDay(n);
}
}
|
PHP
<?php
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" );
}
{
$n = 129600;
ConvertSectoDay( $n );
return 0;
}
?>
|
Javascript
<script>
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 " );
}
var n = 129600;
ConvertSectoDay(n);
</script>
|
Output
1 days 12 hours 0 minutes 0 seconds
Time Complexity: O(1)
Auxiliary Space: O(1)
Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!