forked from Dashark/hello-world
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datetime.cpp
54 lines (51 loc) · 1.21 KB
/
datetime.cpp
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
#include <iostream>
class DateTime {
private:
static int sth;
int year, month, day;
int hour, minute, second;
public:
DateTime();
DateTime(int y, int m, int d, int hour, int minute, int second);
DateTime(const DateTime &dt);
~DateTime();
static void showTime();
void showMoon(); //作业:将当前公历转换为农历显示出来
};
int DateTime::sth = 0;
int main() {
DateTime dt, dt1(2020, 3, 27, 10, 40, 55);
DateTime dt2(dt), &dt3 = dt;
DateTime *dt4 = &dt;
dt.showTime();
dt1.showTime();
dt2.showTime();
dt3.showTime();
dt4->showTime();
return 0;
}
DateTime::DateTime()
{
year = 2020; month = 3; day = 20;
hour = 11; minute = 27; second = 55;
sth = 11;
}
DateTime::DateTime(int y, int m, int d, int hour, int minute, int second)
{
year = y; month = m; day = d;
this->hour = hour; this->minute = minute; this->second = second;
}
DateTime::DateTime(const DateTime &dt)
{
year = dt.year; month = dt.month; day = dt.day;
hour = dt.hour; minute = dt.minute; second = dt.second;
}
DateTime::~DateTime()
{
std::cout << " Go die, Ha~Ha~" << std::endl;
}
void DateTime::showTime()
{
printf("当前时间:%d/%d/%d %d:%d:%d\n", year, month, day, hour, minute, second);
std::cout << sth << std::endl;
}