프로그래밍
[win32] SystemTimeToVariantTime() 밀리세컨드 제외 변환문제
Mesia
2015. 10. 10. 09:14
증상
원인
해결방법
Windows NT 4.0 서비스 팩 4 (SP4), Windows 95 사용 하 여 구성 요소 개체 모델 DCOM (분산) 1.2 및 Windows 98 부터는 이제 자동화 지원 전달 사용자 정의 형식 (Udt) 변형 및 사용자 정의 형식의 기록할 때 메서드에 인수로. Udt 반환 방법 허용 하 고 구조에 대 한 포인터를 필요로 하는 메서드를 호출 하도록 (자동화 클라이언트) 자동화 컨트롤러의 프로그래머가. 위에서 언급 한 함수를 사용 하는 대신, 사용자에 게 SYSTEMTIME 구조를 줄 바꿈 수 있으며 자동화 인터페이스를 사용자 정의 데이터 형식을 전달할 수 있습니다.
상태
추가 정보
#include "stdafx.h"
#include <ole2.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
SYSTEMTIME stNow1, stNow2;
GetSystemTime(&stNow1);
stNow2 = stNow1;
// Set different values for milliseconds.
stNow1.wMilliseconds =10;
stNow2.wMilliseconds =0;
printf("SystemTime with Milliseconds:\n"
"Hours: %d, Minutes: %d, Seconds: %d, Milliseconds: %d\n",
stNow1.wHour, stNow1.wMinute, stNow1.wSecond, stNow1.wMilliseconds);
printf("SystemTime without Milliseconds:\n"
"Hours: %d, Minutes: %d, Seconds: %d, Milliseconds: %d\n",
stNow2.wHour, stNow2.wMinute, stNow2.wSecond, stNow2.wMilliseconds);
double dTime1,dTime2;
SystemTimeToVariantTime (&stNow1,&dTime1);
SystemTimeToVariantTime (&stNow2,&dTime2);
printf("VariantTime from SystemTime with Milliseconds: "
"%0.9f\n", dTime1);
printf("VariantTime from SystemTime without Milliseconds: "
"%0.9f\n", dTime2);
printf("(Both of the above values are same, which shows that the\n"
"SystemTimeToVariantTime conversion routine ignores Milliseconds)");
// Calculate a variant time with milliseconds.
// For example, .840845486 portion of 37085.840845486 corresponds
// to 20 hours, 10 minutes, 49 seconds, and 50 milliseconds.
dTime1 = 37085.840845486;
printf("\n\nVariantTime with Milliseconds: %0.9f \n", dTime1);
printf("SystemTime corresponding to above variant date:\n"
"Hours: 20, Minutes: 20, Seconds: 49, Milliseconds: 50\n");
SYSTEMTIME stCheck;
VariantTimeToSystemTime(dTime1,&stCheck);
printf("Value of Milliseconds in SystemTime after conversion: %d\n",
stCheck.wMilliseconds );
printf("(The above value shows that the VariantTimeToSystemTime\n"
"conversion routine ignores Milliseconds)\n\n");
return 0;
}
참고자료: https://support.microsoft.com/ko-kr/kb/297463