Nevis,
1) COleDateTime :
COleDateTime m_DateTime = COleDateTime::GetCurrentTime();
int nTmp = 0;
nTmp = m_DateTime.GetDay();
nTmp = m_DateTime.GetMonth();
nTmp = m_DateTime.GetYear();
i t.d. - smotri msdn (ja prosto dni nedeli ne ispolzowala)
2) ispolzowanie standartnih c/c++ - funkzii date/time :
//*********************************************
// find interval between two time_t
//*********************************************
bool checkDateInterval(const char* pStrNow_in, const char* pStrCreateDate_in,
int* nDiff_out)
{
#ifdef __cplusplus
try
{
#endif
bool bIsOk = true;
time_t tmpDT1, tmpDT2;
// convert string - Type in DateTime - Type
bIsOk = convertStrToDate(pStrNow_in, &tmpDT1);
if (bIsOk)
bIsOk = convertStrToDate(pStrCreateDate_in, &tmpDT2);
if (bIsOk)
{
// calculate difference
*nDiff_out = ( difftime(tmpDT1, tmpDT2) / (24*60*60) ) -1;
if ( (*nDiff_out) < -10000)
{
trace("checkDateInterval", "nDiff_out < 0", false);
m_nErrCode = generalErr;
bIsOk = false;
}
}
return bIsOk;
#ifdef __cplusplus
}
catch(...)
{
trace("checkDateInterval", "error", true);
return false;
}
#endif
}
//*********************************************
// get current date
//*********************************************
void getCurDate(char* buf)
{
#ifdef __cplusplus
try
{
#endif
// get Now
time_t pTmpDT;
#ifndef __cplusplus
struct tm* pTmpDTTm = NULL;
#else
tm* pTmpDTTm = NULL;
#endif
time(&pTmpDT);
pTmpDTTm = localtime(&pTmpDT);
// convert to char
convertDateToStr(buf, pTmpDTTm);
return;
#ifdef __cplusplus
}
catch(...)
{
trace("getCurDate", "Internes Fehler", true);
return;
}
#endif
}
//*********************************************
// convert string to time_t
//*********************************************
bool convertStrToDate(const char* buf, time_t* pTmpDT)
{
#ifdef __cplusplus
try
{
#endif
bool bIsOk = true;
char strSep[5], *pStrTmp = NULL, strTmp[BUFFER_SIZE];
int nDate[3], i;
#ifndef __cplusplus
struct tm* tmnow = NULL;
#else
tm* tmnow = NULL;
#endif
time_t tmpDT;
strcpy(strSep, ".");
strcpy(strTmp, buf);
// razbiraem string po chastjam (z.B. "22.01.2004") s pom Separator "."
for (i = 0; i < 3; i++)
{
if (i == 0)
{
pStrTmp = strtok(strTmp, strSep);
}
else
{
if(pStrTmp != NULL)
{
pStrTmp = strtok(NULL, strSep);
}
}
if(pStrTmp != NULL)
nDate[i] = atoi(pStrTmp); // [0] - d, [1] - m, [2] - y
}
// set the value
time(&tmpDT);
// convert in -tm-
tmnow = localtime(&tmpDT);
// ustanawliwaem prawilnie znachenija
tmnow->tm_mday = nDate[0];
tmnow->tm_mon = nDate[1] - 1;
tmnow->tm_year = nDate[2] - 1900;
// convert in -time_t-
tmpDT = mktime(tmnow);
*pTmpDT = tmpDT;
return bIsOk;
#ifdef __cplusplus
}
catch(...)
{
trace("convertStrToDate", "error", true);
return false;
}
#endif
}
//*********************************************
// convert tm to string
//*********************************************
void convertDateToStr(char* buf,
#ifndef __cplusplus
const struct tm* pTmpDT)
#else
const tm* pTmpDT)
#endif
{
#ifdef __cplusplus
try
{
#endif
int d, m, y;
char buf1[128];
strcpy(buf1, "");
if (buf)
strcpy(buf, "");
else
return;
d = pTmpDT->tm_mday;
m = pTmpDT->tm_mon + 1;
y = pTmpDT->tm_year + 1900;
sprintf(buf1, "%d", d);
if (d < 10)
strcat(buf, "0");
strcat(buf, buf1);
strcat(buf, ".");
sprintf(buf1, "%d", m);
if (m < 10)
strcat(buf, "0");
strcat(buf, buf1);
strcat(buf, ".");
sprintf(buf1, "%d", y);
strcat(buf, buf1);
return;
#ifdef __cplusplus
}
catch(...)
{
trace("convertDateToStr", "error", true);
return;
}
#endif
}
esli est woprosi - skagi. nadejus, chto hot nemnogo tebe pomogla.