码迷,mamicode.com
首页 > 其他好文 > 详细

获得精确时间到微秒

时间:2017-12-01 23:42:10      阅读:391      评论:0      收藏:0      [点我收藏+]

标签:return   window   time   mil   pre   desktop   mtime   stdio.h   pps   

#include "windows.h"
#include "stdio.h"
#include "inttypes.h"
int main()
{
	FILETIME flt;
	SYSTEMTIME st, lot;
	__int64 wintime;
	__int64 seconds;
	__int64 nano_seconds;
	int milliseconds;
	int microsecond;
	
	// Windows 2000 Professional [desktop apps | UWP apps]
	GetSystemTimeAsFileTime((FILETIME*)&wintime);

	// Windows 8 [desktop apps | UWP apps]
	//GetSystemTimePreciseAsFileTime((FILETIME*)&wintime);
	
	wintime      -=116444736000000000; 
	seconds = wintime / 10000000;
	nano_seconds = wintime % 10000000 * 100;
	milliseconds = nano_seconds / 1000000;
	microsecond = (nano_seconds - milliseconds * 1000000)/100;
	
	//printf("The file time is: seconds %lld nano-seconds %lld   milliseconds %d %ld\n", 
	//    seconds, nano_seconds, milliseconds, microsecond);

	FileTimeToSystemTime((FILETIME*)&wintime, &st);
	FileTimeToLocalFileTime((FILETIME*)&wintime, &flt);
	FileTimeToSystemTime(&flt, &lot);

	printf("The system time is: %02d:%02d:%02d.%03d.%04d \n", 
	    st.wHour, st.wMinute , st.wSecond, milliseconds, microsecond);

	printf("The local  time is: %02d:%02d:%02d.%03d.%04d \n", 
	    lot.wHour, lot.wMinute , lot.wSecond, milliseconds, microsecond);
	return 0;
}

输出
The system time is: 13:08:30.045.2907
The local  time is: 21:08:30.045.2907

获得精确时间到微秒

标签:return   window   time   mil   pre   desktop   mtime   stdio.h   pps   

原文地址:http://www.cnblogs.com/nlsoft/p/7944460.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!