做个小记号,前天昨天都在尝试编译MPlayer,很遗憾还没成功,我想让我小板子跑起视频的愿望还没实现,今天用到的时间函数先做个记录吧
Windows版本,获取当前毫秒数,以及如何得到当前年月日时间等,主要用到_ftime, localtime函数,还有一个time()函数则只能得到秒数,没有毫秒
time_t now;
struct tm mylocaltime;
struct _timeb timebuffer;
struct tm * newtime;
unsigned short millitm1;
_ftime( &timebuffer);
now = timebuffer.time;
millitm1 = timebuffer.millitm;
newtime = localtime(&now);
mylocaltime = *newtime;
fprintf(log_file(), "[%d-%d-%d %02d:%02d:%02d:%ld",
mylocaltime.tm_year + 1900, mylocaltime.tm_mon + 1, mylocaltime.tm_mday,
mylocaltime.tm_hour, mylocaltime.tm_min, mylocaltime.tm_sec, millitm1);
linux则用下面这两个函数
gettimeofday(&now, NULL);
localtime_r(&now.tv_sec, &mylocaltime);
fprintf( "[%d-%d-%d %02d:%02d:%02d:%ld",
mylocaltime.tm_year + 1900, mylocaltime.tm_mon + 1, mylocaltime.tm_mday,
mylocaltime.tm_hour, mylocaltime.tm_min, mylocaltime.tm_sec, now.tv_usec / 1000);