struct tm

{

int tm_sec; /* Seconds. [0-60] (1 leap second) */

int tm_min; /* Minutes. [0-59] */

int tm_hour; /* Hours. [0-23] */

int tm_mday; /* Day. [1-31] */

int tm_mon; /* Month. [0-11] */

int tm_year; /* Year - 1900. */

int tm_wday; /* Day of week. [0-6] */

int tm_yday; /* Days in year.[0-365] */

int tm_isdst; /* DST. [-1/0/1]*/

#ifdef __USE_BSD

long int tm_gmtoff; /* Seconds east of UTC. */

__const char *tm_zone; /* Timezone abbreviation. */

#else

long int __tm_gmtoff; /* Seconds east of UTC. */

__const char *__tm_zone; /* Timezone abbreviation. */

#endif

};

在C语言中

有time_t tm timeval等几种类型的时间

1.time_t为typedef __int64 __time64_t;

2.struct timeval

{

uint tv_sec;

uint tv.usec;

}

具体操作函数

包含文件:<sys/time.h> <time.h>

tm *gmtime(time_t * t);

time_t time(time_t *t);

char *asctime(const struct tm *timeptr);

char *ctime(const time_t *timer);

把tm指针转换为time_t

time_t mktime(struct tm *timeptr);

localtime和gmtime的区别在于gmtime将时间转换为国际标准格式,也就是相对于1970 00:00:00开始的时间戳

而localtime是相对于本地的时区的格式。

#include<stdio.h>

#include<time.h>

#include<sys/time.h>

#include<signal.h>

#include<pthread.h>

void quit_t()

{

printf("eixt now");

exit(-1);

}

int main()

{

/* struct timeval vt;

gettimeofday(&vt , NULL);

while(1)

{

printf("%u:%u\n",vt.tv_sec,vt.tv_usec);

sleep(2);

signal(SIGINT, quit_t);

}

*/

struct tm *tt;

time_t t = time(NULL);

tt = gmtime(&t);

//char *s = asctime(tt);

printf("%d-%d-%d %d:%d:%d",tt->tm_year+1900,tt->tm_mon+1,tt->tm_mday,tt->tm_hour,tt->tm_min,tt->tm_sec);

return 0;

}

#ifndef _TM_DEFINED

struct tm {

int tm_sec; /* 秒 - 取值区间为[0,59] */

int tm_min; /* 分 - 取值区间为[0,59] */

int tm_hour; /* 时 - 取值区间为[0,23] */

int tm_mday; /* 一个月中的日期 - 取值区间为[1,31] */

int tm_mon; /* 月份(从一月开始,0代表一月)- 取值区间为[0,11] */

int tm_year; /* 年份,其值等于实际年份减去1900 */

int tm_wday; /* 星期–取值区间为[0,6],其中0代表星期天,1代表星期一,以此类推 */

int tm_yday; /* 从每年的1月1日开始的天数 – 取值区间为[0,365],其中0代表1月1日,1代表1月2日,以此类推 */

int tm_isdst; /*夏令时标识符,实行夏令时的时候,tm_isdst为正。不实行夏令时的进候,tm_isdst为0;不了解情况时,tm_isdst()为负。*/

};

#define _TM_DEFINED /* 避免重复定义 tm */

#

endif

ANSI C标准称使用tm结构的这种时间表示为分解时间(broken-down time)。

包含文件:<sys/time.h> <time.h>

把tm指针转换为time_t: time_t mktime(struct tm *timeptr);

最新文章

  1. java.lang.IllegalStateException: Web app root system property already set to different value
  2. Node.js&#160;的初步理解
  3. linux pipe
  4. JSX架构及注释
  5. commondline 之一 常识
  6. POJ 1062 昂贵的聘礼(Dijkstra)
  7. sql 事务处理
  8. Gradle Goodness: Set Java Compiler Encoding--转载
  9. C#学习笔记11:C#中的顺序结构、分支结构、循环结构
  10. solr 搜索引擎及搜索推荐应用
  11. VS2015 Cordova Ionic移动开发(一)
  12. C语言--关键字 typedef
  13. I/O浅析
  14. C语言之强化,弱化符号weak
  15. bzoj 3629 聪明的燕姿 约数和+dfs
  16. webpack 打包测试和生产多个版本
  17. 响应式网站设计(Responsive Web design)
  18. SOA和微服务架构的区别?
  19. 利用阿里云提供的镜像快速更换本地的yum源
  20. Python——脚本(calculator)

热门文章

  1. linux下从一台服务器复制文件或文件夹到本地
  2. 【转】WPF Template模版之DataTemplate与ControlTemplate的关系和应用(二)
  3. windows 端口被占用,并杀死进程的方法
  4. 【Clojure 基本知识】小技巧s
  5. Unity编辑器中分割线拖拽的实现
  6. 转:The Difference Between a LayoutTransform and a RenderTransform
  7. Linux set、env、declare、export显示shell变量的区别
  8. exception ‘PHPExcel_Calculation_Exception‘ with message ‘粉丝数据!C2679 -&gt; Formula Error: Operator ‘=‘ has no operands
  9. 理解vue之element-ui中的 &lt;template slot-scope=&quot;scope&quot;&gt;
  10. windows 下安装 mongodb 时间太久,卡在那里不动