?? customertime.cpp
字號:
#include "CustomerTime.h"
#include <stdio.h>
#include <time.h>
#include <iostream>
#include <iomanip>
using namespace std;
const int monthDay[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
void Time::setTime(int y, int m, int d, int h, int min)
{
year = y;
month = m;
day = d;
hour = h;
minute = min;
}
Time::Time(int y, int m, int d, int h, int min)
{
char tmpTime[20], tmpDate[20];
_strtime(tmpTime);
_strdate(tmpDate);
sscanf(tmpDate, "%d/%d/%d", &month, &day, &year);
sscanf(tmpTime, "%d:%d", &hour, &minute);
}
void Time::display()
{
cout << setw(2) << setfill('0') << year << '/' << month << '/' << day << " "
<< hour << ':' << minute;
}
int Time::isRYear(int n)
{
if (n % 4 == 0 && (n % 100 != 0 || n % 400 == 0))
return 1;
return 0;
}
int Time::subDay(Time tmpTime)
{
int i, res = 0;
int nowYear = year + 2000;
int tmpYear = tmpTime.getYear() + 2000;
for (i = tmpYear; i < nowYear; i++)
{
if (isRYear(i))
res += 366;
else res += 365;
}
for (i = tmpTime.getMonth(); i < month; i++)
{
res += monthDay[i];
if (i == 2) res += isRYear(nowYear);
}
res += day - tmpTime.getDay();
if (hour > 12) res++;
if (tmpTime.getHour() < 12) res++;
if (!res) res = 1;
return res;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -