工作需要,就写了个时间戳获取方法,主要针对Win32和linux,理论IOS只要使用code编译出来的静态库即可[未尝试]
直接code
//头文件
#include
#include
#ifdef WIN32
#include
#else
#include
#endif
//功能实现
//get the timestamp
time_t tt = time(NULL);
struct tm* ptr;
ptr = localtime(&tt);
printf("time: %d \n", tt);
char str[80];
strftime(str, sizeof(str),"%Y-%m-%d %H:%M:%S",ptr);
char sec[50];
#ifdef WIN32
structtimebtp;
ftime(&tp);
printf("now time: %s.%03d \n", str, tp.millitm);
#else
struct timeval tmv;
gettimeofday(&tmv, NULL);
printf("now time: %s.%03d \n", str, tmv.tv_usec/1000);
#endif 时间仓促,不太完善,请高手指导,也方便以后复用