#include <time.h>
void t3()
{
time_t* lt;
struct tm* t;
lt = (time_t*)malloc(sizeof(time_t));
time(lt);
t = localtime(lt);
printf("%d-%d-%d ", 1900+t->tm_year, 1+t->tm_mon, t->tm_mday);
printf("%d:%d:%d\n", t->tm_hour, t->tm_min, t->tm_sec);
free(lt);
}
得到毫秒时间
void t5()
{
timeb* tb;
int64_t i64;
tb = (timeb*) malloc(sizeof(timeb));
ftime(tb);
i64 = (int64_t)tb->time * 1000 + tb->millitm;
printf("%ld %d\n", tb->time, tb->millitm);
printf("%I64d\n", i64);
free(tb);
}
需要引入的头文件
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
#include <sys/timeb.h>