- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Converting seconds into days, hours, minutes and seconds in C++
In this tutorial, we will be discussing a program to convert seconds into days, hours, minutes and seconds.
For this we will be provided with a random number of seconds. Our task is to convert it into proper number of days, hours, minutes and seconds respectively.
Example
#include <bits/stdc++.h> using namespace std; //converting into proper format void convert_decimal(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 = 126700; convert_decimal(n); return 0; }
Output
1 days 11 hours 11 minutes 40 seconds
- Related Articles
- C++ Program for converting hours into minutes and seconds
- Converting seconds in years days hours and minutes in JavaScript
- Python program to convert seconds into hours, minutes and seconds
- Convert 7290 seconds into hours and minutes.
- MySQL DateTime Now()+5 days/hours/minutes/seconds?
- Add the following:2 hours 13 minutes 40 seconds and 4 hours 23 minutes 35 seconds.
- Subtract 4 hours 20 minutes 36 seconds from 8 hours 18 minutes 20 seconds.
- Convert 40 minutes into seconds.
- Hours and minutes from number of seconds using JavaScript
- How to convert JavaScript seconds to minutes and seconds?
- How can we create a MySQL function to find out the duration of years, months, days, hours, minutes and seconds?
- How to sum time in MySQL by converting into seconds?
- Convert:3 hours and 12 minutes into hours.
- How many seconds are there in $24$ hours?
- What is the ratio between 50 seconds and 10 minutes?

Advertisements