millitime.cpp

来自「使用windows系统中的毫秒时间」· C++ 代码 · 共 40 行

CPP
40
字号
/* FTIME.C: This program uses _ftime to obtain the current
 * time and then stores this time in timebuffer.
 */

#include <stdio.h>
#include <sys/timeb.h>
#include <time.h>
//#include <winbase.h>


void main( void )
{
   int result;
   struct _timeb timebuffer,timebuffer1;
   char *timeline;

   _ftime( &timebuffer );
   timeline = ctime( & ( timebuffer.time ) );

   printf( "The time is %.19s.%hu %s", &timeline[0], timebuffer.millitm, &timeline[20] );

   printf( "The Value of timeline is %s",timeline);

   printf( "The value of timebuffer.millitm is %d\n",timebuffer.millitm);

   for(int i=0;i<9999999*2;i++)
   {
   }
   _ftime( &timebuffer1 );
   printf( "The value of timebuffer.millitm is %d\n",timebuffer1.millitm);
   
   if(timebuffer1.millitm > timebuffer.millitm)
	   result = timebuffer1.millitm - timebuffer.millitm;
   else
	   result = 1000 - timebuffer.millitm + timebuffer1.millitm;
   printf( "The time between two _ftime is %d\n",result);
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?