【原创】C++中时间格式的转换 tm
来源:互联网 发布:ubuntu卸载输入法 编辑:程序博客网 时间:2024/05/29 12:13
struct tm * local;/// 时间格式 2011-09-10-22-30-15
time_t t;/// 时间 LONGLONG 是距离1970年1月1日的时间time(&t);
local = localtime(&t);/// 当前系统时间
printf("Local year is: %d\n",local->tm_year+1900);/// 时间格式中的年份为 +1900 为现在的年份
printf("Local month is: %d\n",local->tm_mon+1);/// 月份为0、1、2、3、4、5、6、7、8、9、10、11
printf("Local day is: %d\n",local->tm_mday);
printf("Local hour is: %d\n",local->tm_hour);
printf("Local minute is: %d\n",local->tm_min);
printf("Local second is: %d\n",local->tm_sec);
printf("UTC hour is: %d\n" , local->tm_hour);
char str[256] = {0};
strftime( str, 128, "Today is%A, day %d of%B in the year %Y.\n",local);/// 通过tm格式可以直接得到 年 月 日
cout<<str<<endl;
time_t tTimea = StringToStructTime("2011-09-10-22-30-15");
int chargeTime = 20;
tTimea +=chargeTime;
struct tm *tTime;
tTime = localtime(&tTimea);
printf("Local year is: %d\n",tTime->tm_year+1900);
printf("Local month is: %d\n",tTime->tm_mon+1);
printf("Local day is: %d\n",tTime->tm_mday);
printf("Local hour is: %d\n",tTime->tm_hour);
printf("Local minute is: %d\n",tTime->tm_min);
printf("Local second is: %d\n",tTime->tm_sec);
char strTime[24] = {0};
sprintf_s(strTime, "%4d-%2d-%2d-%2d-%2d-%2d", tTime->tm_year+1900,tTime->tm_mon+1,tTime->tm_mday,tTime->tm_hour,tTime->tm_min,tTime->tm_sec);
cout<<strTime<<endl;
system("pause");
/// end main
time_t StringToStructTime(char * szTime)
{
struct tm tm1;
time_t time1;
sscanf(szTime, "%4d-%2d-%2d-%2d-%2d-%2d",&tm1.tm_year, &tm1.tm_mon, &tm1.tm_mday, &tm1.tm_hour, &tm1.tm_min,&tm1.tm_sec);
tm1.tm_year -= 1900;
tm1.tm_mon --;
tm1.tm_isdst = -1;
time1 = mktime(&tm1);
return time1;
}
- 【原创】C++中时间格式的转换 tm
- C/C++中time_t、tm、字符串之间的转换
- C语言中两种方式表示时间日期值time_t和struct tm类型的相互转换
- C语言中两种方式表示时间日期值time_t和struct tm类型的相互转换
- C语言中两种方式表示时间日期值time_t和struct tm类型的相互转换
- C语言中两种方式表示时间日期值time_t和struct tm类型的相互转换
- c++;tm;时间类型;
- C/C++ 日期 时间 time_t与struct tm转换
- C/C++ 日期 时间 time_t与struct tm转换收藏
- C/C++ 日期 时间 time_t与struct tm转换
- C/C++ 日期 时间 time_t与struct tm转换 收藏
- C/C++ 日期 时间 time_t 与 struct tm 转换
- C/C++日期时间time_t与struct tm转换
- c,c++中的日期,时间 time_t和 struct tm转换
- C#中时间格式的转换
- ASP中时间格式的转换
- C#中时间格式的转换
- C#中时间格式的转换
- cocos2d Basic Concepts cocos2d 基本概念
- watir 获取页面所有元素
- hadoop中datanode无法启动
- Makefile详解(好!)
- JQuery调用Rest服务接口
- 【原创】C++中时间格式的转换 tm
- 数据挖掘常用算法
- wcdma搜集的基础知识
- PHP最佳实践
- 加限制的最小化的文件
- Oracle中TO_DATE格式
- IOS数组无法添加数据
- YUI Compressor快速使用指南
- 【推荐】LSI(latent semantic indexing) 完美教程