-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTime.h
88 lines (86 loc) · 1.81 KB
/
Time.h
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#pragma once
#include <iomanip>
#include "Appointment.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class Time{
protected:
int Day;
int Month;
int Year;
int Hours;
public:
void update_time();
friend ostream& operator << (ostream& out, const Time& obj);
int getDay(){
return Day;
}
int getMonth(){
return Month;
}
int getYear(){
return Year;
}
int getHours(){
return Hours;
}
};
void Time::update_time() {
time_t t = time(0); // get time now
tm* now = localtime(&t);
cout << (int)(now->tm_year + 1900) << '-'
<< (int)(now->tm_mon + 1) << '-'
<< (int)now->tm_mday
<< "\n";
Year=(int)(now->tm_year + 1900);
Month=(int)(now->tm_mon + 1);
if (Month==1){
Day=0;
} //31 Jump
if (Month==2){
Day=31;
} //28 Jump
if (Month==3){
Day=59;
} //31 Jump
if (Month==4){
Day=90;
} //30 Jump
if (Month==5){
Day=120;
} //31 Jump
if (Month==6){
Day=151;
} //30 Jump
if (Month==7){
Day=181;
} //31 Jump
if (Month==8){
Day=212;
} //31 Jump
if (Month==9){
Day=243;
} //30 Jump
if (Month==10){
Day=273;
} //31 Jump
if (Month==11){
Day=304;
} //30 Jump
if (Month==12){
Day=334;
}
Day+=(int)now->tm_mday;
Hours=(int)(now->tm_hour);
cout<<"Date,Time Updated!";
}
ostream& operator << (ostream& out, const Time& obj)
{
out <<"Year : "<< obj.Year << endl;
out <<"Month: "<<obj.Month<<endl;
out<< "Day : "<<obj.Day<<endl;
out<< "Hour : "<<obj.Hours<<endl;
return out;
}