zoukankan      html  css  js  c++  java
  • 获得毫秒级别的当前时间

    ftime()函数取得目前的时间和日期。

    相关函数:time, ctime, gettimeofday
    表头文件:#include <sys/timeb.h>
    函数定义:int ftime(struct timeb *tp);
    函数说明:ftime()将目前日期由tp所指的结构返回。tp结构定义:

    struct   timeb{
           time_t   time;                      /* 为1970-01-01至今的秒数*/
           unsigned   short   millitm;   /* 千分之一秒即毫秒 */
           short   timezonel;               /* 为目前时区和Greenwich相差的时间,单位为分钟 */
           short   dstflag;                   /* 为日光节约时间的修正状态,如果为非0代表启用日光节约时间修正 */
    };

    示例:

    #include <sys/timeb.h>
    #include <stdarg.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    #include <stdio.h>
    
    main()
    {
          struct timeb tp;
          char ti[32];
          ftime(&tp);
          printf("%lld
    ",tp.time);/*UTC时间1970到现在的秒数*/
          strftime(ti, sizeof(ti), "%Y-%m-%d %H:%M:%S", localtime(&tp.time));
          printf("%s %03u
    ", ti,tp.millitm);
    }
  • 相关阅读:
    使用GitLab搭建Git仓库
    SpringBoot web开发
    springboot配置
    springboot自动配置原理
    springboot修改端口号
    springboot创建方式
    junit运行多个测试的方法
    junit常用注解
    junit断言
    sublime将.m文件关联MATLAB类型高亮
  • 原文地址:https://www.cnblogs.com/bugutian/p/5833285.html
Copyright © 2011-2022 走看看