time_t和struct tm之间的转换
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之间的转换的更多相关文章
- 【转】C/C++中的日期和时间 TIME_T与STRUCT TM转换——2013-08-25 16
http://www.cnblogs.com/Wiseman/archive/2005/10/24/260576.html 摘要: 本文从介绍基础概念入手,探讨了在C/C++中对日期和时间操作所用到的 ...
- C语言中两种方式表示时间日期值time_t和struct tm类型的相互转换
使用gmtime函数或localtime函数将time_t类型的时间日期转换为structtm类型: 使用time函数返回的是一个long值,该值对用户的意义不大,一般不能根据其值确定具体的年.月.日 ...
- struct tm 和 time_t 时间和日期的使用方法(转
关键字:UTC(世界标准时间),Calendar Time(日历时间),epoch(时间点),clock tick(时钟计时单元) .概念 在C/C++中,对字符串的操作有很多值得注意的问题,同样,C ...
- 时间操作(struct tm、time_t)求指定日期 前n天的日期
1.在标准C/C++中,我们可通过tm结构来获得日期和时间,tm结构在time.h中的定义如下: #ifndef _TM_DEFINED struct tm { int tm_sec; /* 秒–取值 ...
- SYSTEMTIME 与 time_t 之间的转换,计算2个SYSTEMTIME的时间差
time_t systemtime_to_time_t(const SYSTEMTIME& st) { struct tm gm = {st.wSecond, st.wMinute, st.w ...
- FlyCapture2 fc2Image OpenCV IplImage Conversion 两种图像格式之间的转换
fc2Image是FlyCapture SDK的C语言库中的图片格式,由于在Windows上的MinGW无法编译FlyCapture2的C++库,只能使用C语言库,所以当我们在同时使用OpenCV的图 ...
- CString-int-string-char-BSTR之间的转换
一.CString, int, string, char*之间的转换 string 转 CString CString.Format("%s", string.c_str());c ...
- 将日期和时间作为 struct tm型的值直接向二进制文件进行读写
#include <stdio.h> #include <time.h> char data_file[]="D:\\%\\datetime.dat"; v ...
- C++四种类型之间的转换
C风格的强制类型转换(Type Cast)很简单,不管什么类型的转换统统是: TYPE b = (TYPE)a. C++风格的类型转换提供了4种类型转换操作符来应对不同场合的应用. const_cas ...
随机推荐
- 李洪强漫谈iOS开发[C语言-023]-取余数运算符
- 166. Fraction to Recurring Decimal
题目: Given two integers representing the numerator and denominator of a fraction, return the fraction ...
- windows 下 使用codeblocks 实现C语言对python的扩展
本人比较懒就粘一下别人的配置方案了 从这开始到代码 摘自http://blog.csdn.net/yueguanghaidao/article/details/11538433 一直对Python扩展 ...
- 海量数据的二度人脉挖掘算法(Hadoop 实现)
最近做了一个项目,要求找出二度人脉的一些关系,就好似新浪微博的“你可能感兴趣的人” 中,间接关注推荐:简单描述:即你关注的人中有N个人同时都关注了 XXX . 在程序的实现上,其实我们要找的是:若 U ...
- NoClassDefFoundError: javassist/util/proxy/MethodFilter
Caused by: java.lang.NoClassDefFoundError: javassist/util/proxy/MethodFilter at org.hibernate.byt ...
- Redis 如何导出数据
Redis是一款支持多种数据类型的Key-Value数据库. 这里介绍下如何从Redis中导出数据. 数据是如何存储的?. Redis中是把数据保存到内存中的,但是它也会定期的把数据写会到硬盘中. R ...
- 6个可以隐藏运行bat,浏览器等程序的方法
在电脑启动时或者设置时间时运行指定的程序很容易实现.但是有时候还需要运行时不显示主界面,隐藏到后台运行.比如:开机时一段Bat批处理执行删除默认共享; 开机自动运行浏览器隐藏到后代打开指定网页等,希望 ...
- 指令 scope
angular学习笔记(三十)-指令(8)-scope <!DOCTYPE html> <html ng-app="myApp"> <head> ...
- 在User Profile Service中配置AD的同步连接
转:http://www.360sps.com/Item/ConfigureSynchronizationConnections.aspx 如果要将Active Directory.LDAP 目录和业 ...
- Embedding Documents in Word 2007 by Using the Open XML SDK 2.0 for Microsoft Office
Download the sample code This visual how-to article presents a solution that creates a Word 2007 doc ...