封装CTime类CMyTime
来源:互联网 发布:什么是大数据开发 编辑:程序博客网 时间:2024/05/21 18:46
CMyTime.h//
#pragma once
class CMyTime
{
time_t my_time;
public:
static CMyTime GetCurrentTime();
CMyTime() { my_time = 0; }
CMyTime(time_t time)
{
my_time = time;
}
CMyTime(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec, int nDST = -1);
time_t GetTime() const
{
return my_time;
}
int GetYear() const;
int GetMonth() const;
int GetDay() const;
int GetHour() const;
int GetMinute() const;
int GetSecond() const;
int GetDayOfWeek() const;
BOOL operator==(CMyTime time) const
{
return this->my_time == time.my_time;
}
BOOL operator!=(CMyTime time) const
{
return this->my_time != time.my_time;
}
BOOL operator<(CMyTime time) const
{
return this->my_time < time.my_time;
}
BOOL operator>(CMyTime time) const {
return this->my_time > time.my_time;
}
BOOL operator<=(CMyTime time) const
{
return this->my_time <= time.my_time;
}
BOOL operator>=(CMyTime time) const
{
return this->my_time >= time.my_time;
}
};
CMyTime.cpp//
#include "stdafx.h"
#include "MyTime.h"
CMyTime CMyTime::GetCurrentTime()
{
return time(NULL);
}
CMyTime::CMyTime(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec, int nDST)
{
tm timo = { nSec,nMin,nHour,nDay,nMonth-1,nYear-1900 };
my_time = mktime(&timo);
}
int CMyTime::GetYear() const
{
tm timo;
localtime_s(&timo, &my_time);
return timo.tm_year + 1900;
}
int CMyTime::GetMonth() const
{
tm timo;
localtime_s(&timo, &my_time);
return timo.tm_mon + 1;
}
int CMyTime::GetDay() const
{
tm timo;
localtime_s(&timo, &my_time);
return timo.tm_mday;
}
int CMyTime::GetHour() const
{
tm timo;
localtime_s(&timo, &my_time);
return timo.tm_hour;
}
int CMyTime::GetMinute() const
{
tm timo;
localtime_s(&timo, &my_time);
return timo.tm_min;
}
int CMyTime::GetSecond() const
{
tm timo;
localtime_s(&timo, &my_time);
return timo.tm_sec;
}
int CMyTime::GetDayOfWeek() const
{
tm timo;
localtime_s(&timo, &my_time);
return timo.tm_wday + 1;
}
- 封装CTime类CMyTime
- MFC自己封装的CMytime类
- CTime类
- CTime类
- CTime类
- CTime类
- CTime类
- CTime类
- VC++ CTime类,CTime 与 CString转换
- CTime类,CTime 与 CString转换
- COleDateTime类 CTime类
- CTime类使用大全
- CTime类的用法
- CTime类小结
- CTime类使用小结
- MFC常用类CTime
- CTime类操作
- MFC CTime类使用方法
- leetcode[Minimum Absolute Difference in BST]//待整理多种解法
- 一个诡异的Java问题
- COJ1979-古怪的行列式
- VMWare创建虚拟机提示长模式未开启??
- 2017百度之星初赛(A) 1001 小C的倍数问题(余数定理)
- 封装CTime类CMyTime
- MVG读书笔记——三维空间中的射影几何(一)
- 华为历年机考题收录
- RH134-第二十三节-DNS高速缓存
- java class文件结构
- 做项目遇到的java弹框1
- FTPrep, 35 Search Insert Position
- c++入门教程(八)
- codeforces #428 Div.2 C