//LF_DateTime.h
#include <time.h>
class CLF_DateTime
{
private:
struct tm *local;
time_t t;
char str[80];
public:
CLF_DateTime(int year, int month, int day,int hour, int min,int sec);
~CLF_DateTime(void);
void display(char* strdisplay);
};
//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;
local->tm_mon = month;
local->tm_mday = day;
local->tm_hour =0;
local->tm_min =0;
local->tm_sec =0;
}
CLF_DateTime::~CLF_DateTime(void)
{
delete(local);
}
void CLF_DateTime::display(char* strdisplay)
{
strftime(str,80,"%Y-%m-%d %H:%M:%S",local);
cout<<str<<endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
CLF_DateTime *pa;
char testdisplay[256];
pa = new CLF_DateTime(2005,10 ,01 , 11,50,23);
pa->display(testdisplay);
cout<<testdisplay<<endl;
return 0;
}
编译可以通过!但执行后出现的都是乱码!我想要的结果应该是"2005-10-01 11:50:23"