• 获得精确时间到微秒


    #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
    ", 
    	//    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 
    ", 
    	    st.wHour, st.wMinute , st.wSecond, milliseconds, microsecond);
    
    	printf("The local  time is: %02d:%02d:%02d.%03d.%04d 
    ", 
    	    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
    
  • 相关阅读:
    Spring + SpringMVC + MyBatis
    jquery+bootstrap使用数字增减按钮
    Eclipse添加代码注释模板
    No goals have been specified for this build
    字符串前面自动补零
    深入理解JavaScript系列
    java判断A字符串是否包含B字符串
    WebSocket 实战
    button点击切换,获取按钮ID
    JS 中判断空值 undefined 和 null
  • 原文地址:https://www.cnblogs.com/nlsoft/p/7944460.html
Copyright © 2020-2023  润新知