linux

#include <stdio.h>
#include <time.h>

int main(int argc,char **argv)
{
    //两种时间的获取方法
    struct timeval tv;
    gettimeofday(&tv,NULL);
    time_t t=time(0);
    printf("%u---%u+++%u\n",tv.tv_sec,tv.tv_usec,t);
    //时间格式转换
    char tmp[64];
    strftime(tmp,sizeof(tmp),"%Y%m%d%H%M%S\n",localtime(&t));
    printf("%s",tmp);
    return 0;
}

windows

#include <stdio.h>
#include <time.h>

int main(int argc, char* argv[])
{
    //windows没有timeval结构,当然也没有gettimeofday函数
    //struct timeval tv;
    //gettimeofday(&tv,NULL);
    
    time_t t=time(0);
    char tmp[64];
    strftime(tmp,sizeof(tmp),"%Y%m%d-%H%M%S",localtime(&t));
    printf("%s",tmp);
    
    return 0;
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-01
  • 2021-04-26
  • 2022-01-19
  • 2021-08-04
猜你喜欢
  • 2021-10-22
  • 2021-06-14
  • 2022-12-23
  • 2022-03-06
  • 2022-12-23
  • 2022-12-23
  • 2021-07-14
相关资源
相似解决方案