Chào mừng đến với Diễn đàn lập trình - Cộng đồng lập trình.
Kết quả 1 đến 2 của 2
  1. #1
    Ngày tham gia
    Sep 2015
    Bài viết
    0

    VC++ convert double -> SYSTEMTIME VariantTimeToSystemTimeWithMilliseconds

    Mã:
    BOOL VariantTimeToSystemTimeWithMilliseconds (/*input*/ double
    		dVariantTime, /*output*/SYSTEMTIME *st);
    trong bài cSDL của em có hàm như thế này

    Mã:
    bool CTable::Get(char* FieldName, SYSTEMTIME& st)
    {
    	_variant_t vtValue;
    	vtValue = m_Rec->Fields->GetItem(FieldName)->GetValue();
    
    	if (vtValue.vt == VT_NULL) {
    		return false;
    	}
    	VariantTimeToSystemTimeWithMilliseconds (vtValue.date, &st);
    	return true;
    }
    và hàm VariantTimeToSystemTimeWithMilliseconds thì không được định nghĩa,em biết ý nghĩa của nó dùng để đổi từ double -> SYSTEMTIME nhưng không biết xây dựng nó thế nào,xin anh em cho ý kiến

  2. #2
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    à đây rồi
    Mã:
    BOOL CSysTimeConversionDlg::VariantTimeToSystemTimeWithMilliseconds 
                      (/*input*/ double dVariantTime, /*output*/SYSTEMTIME *st)
    {
        BOOL retVal = TRUE;
    
        double halfsecond = ONETHOUSANDMILLISECONDS / 2.0; 
        // ONETHOUSANDMILLISECONDS is equal to 0.0000115740740740
    
    
    
        retVal = VariantTimeToSystemTime(dVariantTime - halfsecond, st); 
        // this takes care of rounding problem with 
    
        // VariantTimetoSystemTime function
    
        if (retVal == FALSE)
        {
            return retVal;
        }
    
    
        double fraction = dVariantTime - (int) dVariantTime; 
        // extracts the fraction part
    
    
        double hours; 
        hours = fraction = (fraction - (int)fraction) * 24;
    
        double minutes;
        minutes = (hours - (int)hours) * 60;
    
        double seconds;
        seconds = (minutes - (int)minutes) * 60;
    
        double milliseconds;
        milliseconds = (seconds - (int)seconds) * 1000;
    
        milliseconds = milliseconds + 0.5; // rounding off millisecond to the 
    
                                           // nearest millisecond 
    
        if (milliseconds < 1.0 || milliseconds > 999.0) //Fractional 
    
                              // calculations may yield in results like
    
            milliseconds = 0; // 0.00001 or 999.9999 which should actually 
    
                              // be zero (slightly above or below limits 
    
                              // are actually zero)
    
    
        if (milliseconds) 
            st->wMilliseconds = (WORD) milliseconds;
        else  // if there is 0 milliseconds, then we don't have the problem !!
    
            retVal = VariantTimeToSystemTime(dVariantTime, st); // 
    
    
        return retVal;
    }
    http://www.codeproject.com/KB/dateti...WMillisec.aspx

 

 

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •