吕鑫书中自己定义的CMyTime
来源:互联网 发布:一木成林软件 编辑:程序博客网 时间:2024/06/03 13:33
//mian函数// 15.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "MyTime.h"#include <iostream>using namespace std;int main(int argc, char* argv[]){ CMyTime t1,t2;t2=t1.GetCurrentTime();int day=t2.GetMonth(); cout<<"today is:"<<day<<endl;return 0;}
//定义的类头文件// MyTime.h: interface for the CMyTime class.////////////////////////////////////////////////////////////////////////#if !defined(AFX_MYTIME_H__D7793E59_8A7A_4BB7_89E3_DC3E6CC7CA8E__INCLUDED_)#define AFX_MYTIME_H__D7793E59_8A7A_4BB7_89E3_DC3E6CC7CA8E__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000//#include "stdafx.h"#include "time.h"#include "assert.h"#include "Windows.h"class CMyTime {public:BOOL operator==(CMyTime t1)const; int GetDayOfWeek()const;int GetSec()const;int GetMin()const;int GetHour()const;int GetDay()const;int GetMonth()const;int GetYear()const;time_t GetTime()const;static CMyTime GetCurrentTime();CMyTime();CMyTime(time_t time);CMyTime(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec,int nDST=-1);virtual ~CMyTime();private:time_t m_time;};#endif // !defined(AFX_MYTIME_H__D7793E59_8A7A_4BB7_89E3_DC3E6CC7CA8E__INCLUDED_)//类的实现// MyTime.cpp: implementation of the CMyTime class.////////////////////////////////////////////////////////////////////////#include "stdafx.h"#include "MyTime.h"#include "time.h"#include "assert.h"#include "windef.h"//////////////////////////////////////////////////////////////////////// Construction/Destruction//////////////////////////////////////////////////////////////////////CMyTime::CMyTime(){}CMyTime::~CMyTime(){}CMyTime::CMyTime(time_t t){m_time=time(&t);}CMyTime::CMyTime(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec,int nDST){struct tm atm;atm.tm_sec = nSec;atm.tm_min = nMin;atm.tm_hour = nHour;assert(nDay >= 1 && nDay <= 31);atm.tm_mday = nDay;assert(nMonth >= 1 && nMonth <= 12);atm.tm_mon = nMonth - 1; // tm_mon is 0 basedassert(nYear >= 1900);atm.tm_year = nYear - 1900; // tm_year is 1900 basedatm.tm_isdst = nDST;m_time = mktime(&atm);assert(m_time != -1); // indicates an illegal input time}CMyTime CMyTime::GetCurrentTime(){ CMyTime t;t.m_time=time(NULL);return t;}time_t CMyTime::GetTime()const{ return time(NULL);}int CMyTime::GetYear()const{ tm *p=localtime(&m_time);return p->tm_year+1900;}int CMyTime::GetMonth()const{ tm *p=localtime(&m_time);return p->tm_mon+1;}int CMyTime::GetDay()const{ tm *p=localtime(&m_time);return p->tm_mday;}int CMyTime::GetHour()const{ tm *p=localtime(&m_time);return p->tm_hour;}int CMyTime::GetMin()const{ tm *p=localtime(&m_time);return p->tm_min;}int CMyTime::GetSec()const{ tm *p=localtime(&m_time);return p->tm_sec;}int CMyTime::GetDayOfWeek()const{ tm *p=localtime(&m_time);return p->tm_wday;}BOOL CMyTime::operator==(CMyTime t1)const{ tm *p1=localtime(&this->m_time);tm *p2=localtime(&t1.m_time);if((p1->tm_year==p2->tm_year)&&(p1->tm_mon==p2->tm_mon))return TRUE;elsereturn FALSE;}
阅读全文
0 0
- 吕鑫书中自己定义的CMyTime
- MFC自己封装的CMytime类
- 自己定义的格式
- 定义自己的Adapter
- 定义自己的异常
- 定义自己的快捷键
- 定义自己的View
- 定义自己的xml
- 定义自己的dialog
- 定义自己的dialog
- 定义自己的g_signal
- 定义自己的错误代码
- 定义自己的QMessageBox
- 定义自己的ViewGroup
- 定义自己的错误代码
- 定义自己的CellEditor
- 如何定义自己的迭代器
- 定义自己的assert语句
- view的CustomBanner轮播
- web开发者工具插件
- Python的学习&文件
- ShoneSharp语言(S#)的设计和使用介绍系列(2)— 掀开盖头
- DSSM, 深度语义匹配模型
- 吕鑫书中自己定义的CMyTime
- python基础8:面向对象3、异常、模块
- CMD命令
- eclipase的快捷键的使用
- LeetCode 92. Reverse Linked List II
- 冒泡排序
- Java Finally
- MyEclipse tomcat start后弹出class.class
- 7.7递归法求最大公约数(3)