//LF_DateTime.h
#include <time.h>
class CLF_DateTime
{
private:
struct tm *local;
public:
CLF_DateTime(int year, int month, int day,int hour, int min,int sec);
~CLF_DateTime(void);
void display(char * strdisplay);
void setdisplay(char * setstrdisplay);
};
//LF_DateTime.cpp
#include "LF_DateTime.h"
#include <time.h>
#include <iostream>
using namespace std;
CLF_DateTime::CLF_DateTime(int year, int month, int day,int hour, int min,int sec)
{
local = new tm;
local->tm_year = year-1900;//struct tm中定义的年成员tm_year是以1900为基数的,也就是说他显示2007时tm_year值并不是2007
local->tm_mon = month-1;//月份可见definition里有说明是[0,11]所以比现实小了一个月
local->tm_mday = day;
local->tm_hour =hour;
local->tm_min =min;
local->tm_sec =sec;
}
CLF_DateTime::~CLF_DateTime(void)
{
delete(local);
}
void CLF_DateTime::display(char * strdisplay)
{
cout<<"Your input date and time is: ";
strftime(strdisplay,80,"%Y-%m-%d %H:%M:%S",local);
cout<<strdisplay<<endl;
system("pause");
}
void CLF_DateTime::setdisplay(char * setstrdisplay)
{
cout<<"Provide rounding:";
if (local->tm_sec>=30&&local->tm_sec<=60)
{
local->tm_min+1&&local->tm_sec==00;
strftime(setstrdisplay,80,"%Y-%m-%d %H:%M:%S",local);
cout <<setstrdisplay<<endl;
system("pause");
else if(local->tm_sec<30&&local->tm_sec>=0)
local->tm_min&&local->tm_sec==00;
strftime(setstrdisplay,80,"%Y-%m-%d %H:%M:%S",local);
cout <<setstrdisplay<<endl;
system("pause");
}
else
cout <<"Input wrong!please input again!"<<endl;
exit(1);
}
int main()
{
CLF_DateTime *pa;
char testdisplay[100];
pa = new CLF_DateTime(2007,11,8,14,50,20);
pa->display(testdisplay);
pa->setdisplay(testdisplay);
return 0;
}
//请大家看看这个程序本身我编的有没有什么问题?我运行的时候总是报"'Debug\TestDateTime.pch' precompiled header file is from a previous version of the compiler, or the precompiled header is C++ and you are using it from C (or vice versa)"错.谢谢!