time_t到struct tm的转换:

#include <time.h>
struct tm *localtime(const time_t *timep);

struct tm到time_t的转换:

#include <time.h>
time_t mktime(struct tm *tm);

time_t timep = time(NULL);能够获得从此刻距1970-01-01 00:00:00 +0000 (UTC)时间点的秒数。

演示样例程序;

#include <stdio.h>
#include <stdlib.h>
#include <time.h> int main (int argc, char **argv)
{
int i;
time_t timer[4];
struct tm tm, *p; tm.tm_year = 2015;
tm.tm_mon = 2;
tm.tm_mday = 23;
tm.tm_hour = 8;
tm.tm_min = 22;
tm.tm_sec = 0;
for(i = 0; i < 4; i++){
timer[i] = mktime(&tm);
printf ("timer[%d] = %ld\n", i, timer[i]);
p = localtime(&timer[i]);
printf("%d-%d-%d-%d-%d-%d\n",
p->tm_year,
p->tm_mon,
p->tm_mday,
p->tm_hour,
p->tm_min,
p->tm_sec);
} return 0;
} /* ----- End of main() ----- */

by fulinux <fulinux@sina.com>

blog: blog.csdn.net/fulinus

time_t和struct tm之间的转换的更多相关文章

  1. 【转】C/C++中的日期和时间 TIME_T与STRUCT TM转换——2013-08-25 16

    http://www.cnblogs.com/Wiseman/archive/2005/10/24/260576.html 摘要: 本文从介绍基础概念入手,探讨了在C/C++中对日期和时间操作所用到的 ...

  2. C语言中两种方式表示时间日期值time_t和struct tm类型的相互转换

    使用gmtime函数或localtime函数将time_t类型的时间日期转换为structtm类型: 使用time函数返回的是一个long值,该值对用户的意义不大,一般不能根据其值确定具体的年.月.日 ...

  3. struct tm 和 time_t 时间和日期的使用方法(转

    关键字:UTC(世界标准时间),Calendar Time(日历时间),epoch(时间点),clock tick(时钟计时单元) .概念 在C/C++中,对字符串的操作有很多值得注意的问题,同样,C ...

  4. 时间操作(struct tm、time_t)求指定日期 前n天的日期

    1.在标准C/C++中,我们可通过tm结构来获得日期和时间,tm结构在time.h中的定义如下: #ifndef _TM_DEFINED struct tm { int tm_sec; /* 秒–取值 ...

  5. SYSTEMTIME 与 time_t 之间的转换,计算2个SYSTEMTIME的时间差

    time_t systemtime_to_time_t(const SYSTEMTIME& st) { struct tm gm = {st.wSecond, st.wMinute, st.w ...

  6. FlyCapture2 fc2Image OpenCV IplImage Conversion 两种图像格式之间的转换

    fc2Image是FlyCapture SDK的C语言库中的图片格式,由于在Windows上的MinGW无法编译FlyCapture2的C++库,只能使用C语言库,所以当我们在同时使用OpenCV的图 ...

  7. CString-int-string-char-BSTR之间的转换

    一.CString, int, string, char*之间的转换 string 转 CString CString.Format("%s", string.c_str());c ...

  8. 将日期和时间作为 struct tm型的值直接向二进制文件进行读写

    #include <stdio.h> #include <time.h> char data_file[]="D:\\%\\datetime.dat"; v ...

  9. C++四种类型之间的转换

    C风格的强制类型转换(Type Cast)很简单,不管什么类型的转换统统是: TYPE b = (TYPE)a. C++风格的类型转换提供了4种类型转换操作符来应对不同场合的应用. const_cas ...

随机推荐

  1. 国内静态文件CDN服务介绍 国内js公共库

    国内静态文件CDN服务介绍 新浪SAE  介绍页 文件页 百度云 介绍页 七牛云存储介绍页 优势,可以提交没有的库,支持https,但证书不可信. 又拍云 介绍页 建议使用阿里云OSS自己上传所需文件 ...

  2. [状压dp]HDU5045 Contest

    题意: n和人做m道题, 每俩人做的题数不能相差一题以上.(也就是每n道题分别由n个人完成)   给n个人分别做m道题的概率, 求完成m题的最大期望 $1\le N \le 10$ 注意!!! fil ...

  3. Android 用Intent和Bundle传递参数

    传递方: //点击btn_sub传递 fieldHeight.getText()和 fieldWeight.getText() private void setListeners()    {    ...

  4. ruby的命名约定

    1 局部变量和方法参数以小写字母开头 2 方法名字以小写字母开头 3 全局变量以$开头 4 实例变量以@开头 5 类变量以@@开头 6 常量以大写字母开头 7  类和模块名以大写字母开头

  5. Linux 启动参数介绍

    Linux 启动参数介绍 取自2.6.18 kernel Documentation/i386/boot.txt 文件中介绍 vga= 这里的不是一个整数(在C语言表示法中,应是十进制,八进制或者十六 ...

  6. 注意!ASP.NET MVC 3 的一个 OutputCache 问题

    在用 ASP.NET MVC 3 重写博客园网站首页时,特地留意了一下这个缓存问题,通过这篇博文分享一下. 在 ASP.NET MVC 3 中如果使用了 OutputCache,一定要在 Action ...

  7. SQL Server 2008空间数据应用系列一:空间信息基础

    转自:http://www.cnblogs.com/beniao/archive/2011/01/18/1933412.html Microsoft SQL Server 2008 提供了全面性的空间 ...

  8. haporoxy的keeplaive ZZ

    转载一个别人总结的http://hi.baidu.com/%D3%E3%B5%C1%B5%C1/blog/item/04ffd1b1854f69ef30add1e8.html httpclose, h ...

  9. [Irving]SQL去重复-DISTINCT用法

    在表中,可能会包含重复值.这并不成问题,不过,有时您也许希望仅仅列出不同(distinct)的值.关键词 distinct用于返回唯一不同的值. 表A: 示例1 select distinct nam ...

  10. 【CSS3】Advanced1:Rounded Corners

    1.Border radius The border-radius property can be used to working clockwise from top-left set border ...