Chinaunix首页 | 论坛 | 博客
  • 博客访问: 384948
  • 博文数量: 102
  • 博客积分: 1395
  • 博客等级: 中尉
  • 技术积分: 1050
  • 用 户 组: 普通用户
  • 注册时间: 2012-11-05 18:09
文章分类

全部博文(102)

文章存档

2013年(25)

2012年(77)

分类: C/C++

2012-11-22 16:07:53

时间类型:
 UTC (Coordinated Universal Time):世界标准时间, 也就是大家所熟知的格林威治时间 GreenWich Mean Time, GMT
 Calendar Time:日历时间, 是用“一个标准时间点 (如: 1970年1月1日0点)到此经过的秒数”来表示时间

  时间获取
  time_t time(time_t *tloc)
功能: 获取日历时间

  时间转化
  struct tm *gmtime(cont time_t *timep)
功能: 将日历时间转换成格林威治时间保存在TM结构中

  struct tm *localtime(const time_t *timep)
功能: 将日历时间转换成本地时间保存在TM结构中

struct tm{
int tm_sec; //秒值
int tm_min; //分钟值
int tm_hour;// 小时值
  int tm_mday;//月的哪一天
int tm_mon;// tm_mon+1 =  当前月份
int tm_year;// tm_year + 1900=哪一年
int tm_wday;//本周的第几日
int tm_yday;//本年第几日
int tm_isdst;//日光节约时间
}

 时间显示
 char *asctime(const struct tm *tm)
功能: 将tm格式的时间转换成字符串形式
 char *ctime(const time_t  *timep)
功能: 将日历时间转换成字符串形式

获取今天的时间
 int gettimeofday(struct timeval *tv, struct timezone *tz
功能: 获取今年凌晨到现在的时间差, 常用于时间的耗时计算
  struct timeval{
int tv_sec;//秒数
int tv_usec; //微秒数
}

程序的延时执行

 unsigned int sleep(unsigned int seconds)
功能:让程序睡眠seconds秒
  unsigned int usleep(unsigned int useconds)
功能: 让程序睡眠useconds微妙

时间编程必备
阅读(865) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~