Getting the current time of day from hour, seconds, and minutes using structure C++

Sep 20, 2018 at 12:11am
How do I even get the time of day in military time from the imputes I would receive from this code? I do not really know to do that. I tried to research some ideas but I am just getting more confused. Is there anything wrong with this code so far? I know it is not completed but I would really appreciate some help.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
#include <cctype>
using namespace std;

struct Time {
	int Min1, Min2, Min3;
} TimeOfDay; 



int main()
{
	int pause;

	cout << "Enter minute #1: " << endl;
	cin >> TimeOfDay.Min1;
	cout << "Enter minute #2: " << endl;
	cin >> TimeOfDay.Min2;
	cout << "Enter minute #3: " << endl;
	cin >> TimeOfDay.Min3;







	


	cin >> pause;
	return 0;

}
Last edited on Sep 20, 2018 at 1:18am
Sep 20, 2018 at 1:02am
I don't understand. What do you mean by "the time of day"? As I understand it, the time of day is the hours, minutes, and seconds since midnight. Isn't that what the user is entering already?
Sep 20, 2018 at 1:13am
Obtaining the current time of day doesn't require you to take user input. I think I don't understand.

You can print the current date (or time, whatever) like this:

1
2
3
4
5
6
7
8
9
10
11
12
#include <chrono>
#include <ctime>
#include <iostream>
#include <iomanip>

using sysclock = std::chrono::system_clock;

int main() 
{
  auto const current_time = sysclock::to_time_t(sysclock::now());
  std::cout << std::put_time(std::localtime(&current_time), "%c\n");
}


Live demo:
http://coliru.stacked-crooked.com/a/21018b4dbaae7b88
Last edited on Sep 20, 2018 at 1:13am
Topic archived. No new replies allowed.