当前时间
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
int main()
{
//<time.h> 精度s
time_t now = time(NULL);
printf("current time: %lds\n", now);
//<sys/time.h> 精度us
struct timeval tval;
gettimeofday(&tval, NULL);
printf("current time: %lds %ldus\n", tval.tv_sec, tval.tv_usec);
//<time.h> 精度ns
struct timespec res;
clock_gettime(CLOCK_REALTIME, &res);
printf("current time: %lds %ldns\n", res.tv_sec, res.tv_nsec);
//<time.h> 讲time_t转换为struct tm
struct tm* t = localtime(&now);
printf("current time: %d/%d/%d %d:%d:%ds\n",
t->tm_year + 1900, t->

最低0.47元/天 解锁文章
3211

被折叠的 条评论
为什么被折叠?



