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\n",tp.time);/*UTC时间1970到现在的秒数*/
      strftime(ti, sizeof(ti), "%Y-%m-%d %H:%M:%S", localtime(&tp.time));
      printf("%s %03u\n", ti,tp.millitm);
}

 

posted on 2016-09-02 14:04  步孤天  阅读(4438)  评论(0编辑  收藏  举报