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);
    }
  • 相关阅读:
    异步任务----django-celery
    signal函数
    shell脚本字符显示颜色
    echo输出到文件
    windows下opencv安装
    模板
    下载vs地址
    关联容器 map
    构造函数初始化列表
    assert() fflush()
  • 原文地址:https://www.cnblogs.com/bugutian/p/5833285.html
Copyright © 2011-2022 走看看