做的atl不能使用MFC, 可是该如何处理 DATE类型???

解决方案 »

  1.   

    这点懒也想偷
    自己去看MFC源代码,照抄就行
      

  2.   

    这是MFC中如何合成DATE类型的源码,你可以参考一下,如果想从DATE获得时间数据,请自行搜索msdn,都在同一个地方呢
    // One-based array of days in year at month start
    AFX_STATIC_DATA int _afxMonthDays[13] =
    {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};/////////////////////////////////////////////////////////////////////////////
    // COleDateTime class HELPERS - implementationAFX_STATIC BOOL AFXAPI _AfxOleDateFromTm(WORD wYear, WORD wMonth, WORD wDay,
    WORD wHour, WORD wMinute, WORD wSecond, DATE& dtDest)
    {
    // Validate year and month (ignore day of week and milliseconds)
    if (wYear > 9999 || wMonth < 1 || wMonth > 12)
    return FALSE; //  Check for leap year and set the number of days in the month
    BOOL bLeapYear = ((wYear & 3) == 0) &&
    ((wYear % 100) != 0 || (wYear % 400) == 0); int nDaysInMonth =
    _afxMonthDays[wMonth] - _afxMonthDays[wMonth-1] +
    ((bLeapYear && wDay == 29 && wMonth == 2) ? 1 : 0); // Finish validating the date
    if (wDay < 1 || wDay > nDaysInMonth ||
    wHour > 23 || wMinute > 59 ||
    wSecond > 59)
    {
    return FALSE;
    } // Cache the date in days and time in fractional days
    long nDate;
    double dblTime; //It is a valid date; make Jan 1, 1AD be 1
    nDate = wYear*365L + wYear/4 - wYear/100 + wYear/400 +
    _afxMonthDays[wMonth-1] + wDay; //  If leap year and it's before March, subtract 1:
    if (wMonth <= 2 && bLeapYear)
    --nDate; //  Offset so that 12/30/1899 is 0
    nDate -= 693959L; dblTime = (((long)wHour * 3600L) +  // hrs in seconds
    ((long)wMinute * 60L) +  // mins in seconds
    ((long)wSecond)) / 86400.; dtDest = (double) nDate + ((nDate >= 0) ? dblTime : -dblTime); return TRUE;
    }