gettimeofday()函数的使用方法

1.函数原型

#include <sys/time.h>

int gettimeofday(struct timeval *tv, struct timezone *tz);

2.说明

gettimeofday()会把目前的时间用tv 结构体返回,当地时区的信息则放到tz所指的结构中

3.结构体

struct  timeval{

long  tv_sec;/*秒*/

long  tv_usec;/*微妙*/

};

struct  timezone{

int tz_minuteswest; /*和greenwich 时间差了多少分钟*/

int tz_dsttime; /*DST的校正*/

}

#include <stdio.h>
#include <time.h>
#include <sys/time.h>
#include <string.h>
#define SIZE_OF_DATETIME 20
int sysUsecTime(char *pTime)
{
struct timeval tv;
struct timezone tz;
struct tm *p;
gettimeofday(&tv, &tz);
p = localtime(&tv.tv_sec);
sprintf(pTime,"%04d%02d%02d%02d%02d%02d%06ld",1900+p->tm_year, 1+p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec, tv.tv_usec);
return 0;
}
int main ()
{
char strusecTime[SIZE_OF_DATETIME+1];
sysUsecTime(strusecTime);
printf("%s\n",strusecTime);
}

最新文章

  1. Android笔记——permission权限大全
  2. fuelphp 问题1
  3. 什么是智能扫描开单打印进销存POS?安卓工业手持PDA设备上的POS销售开单,现场打印打票,用扫描枪太方便了
  4. 证书与keytool
  5. 工作中Linux常用命令
  6. HDU 3537 (博弈 翻硬币) Daizhenyang&#39;s Coin
  7. GreenDao官方文档翻译(下)
  8. Ubuntu下安装配置zsh和oh my zsh
  9. Ping pong
  10. [改善Java代码]使用forName动态加载类文件
  11. 【概率】poj 2096:Collecting Bugs
  12. 简单改造 starling 中的 AssetManager 让其更适合 批次加载纹理
  13. linux修改时区,时间格式
  14. iOS开源项目集合一
  15. nginx利用limit模块设置IP并发防CC攻击
  16. 推荐几个我一直在使用chrome小工具(上)
  17. static方法与非static方法是否可以互相调用
  18. POJ 3348 Cows [凸包 面积]
  19. java 中 printf()语句的理解
  20. [Swift]LeetCode81. 搜索旋转排序数组 II | Search in Rotated Sorted Array II

热门文章

  1. python全栈开发 * 10知识点汇总 * 180612
  2. ionic3.x版本开发问题记录---使用Image Resizer打包报错问题
  3. nlp底层技术列举
  4. 关于systemctl
  5. java框架之Struts2(3)-OGNL&amp;ValueStack
  6. Git环境配置
  7. Clone of COCO API
  8. Python基础(九) type元类
  9. Cisco Packet Tracer
  10. linux 生成密钥,并向git服务器导入公钥