摘:C++日期时间与字符串间的转换
VC6中 CString sTime = _T("2007-10-26 13:20:30"); char *charTime = (LPSTR)(LPCTSTR)sTime; CString sFormat = _T("%d-%d-%d %d:%d:%d"); char *charFormat = (LPSTR)(LPCTSTR)sFormat; int nYear; int nMonth; int nDate; int nHour; int nMin; int nSec; stscanf(charTime,charFormat,&nYear,&nMonth,&nDate,&nHour,&nMin,&nSec); CTime t(nYear,nMonth,nDate,nHour,nMin,nSec); CString s = t.Format(_T("%Y年%m月%d日%H时%M分%S秒")); VC2005中 不含中文格式 stscanf(charTime,charFormat,&nYear,&nMonth,&nDate,&nHour,&nMin,&nSec); CString sTime = _T("2007-10-26 12:40:10"); TCHAR *charTime = (TCHAR*)(LPCTSTR)sTime; CString sFormat = _T("%d-%d-%d %d:%d:%d"); TCHAR *charFormat = (TCHAR*)(LPCTSTR)sFormat; int nYear; int nMonth; int nDate; int nHour; int nMin; int nSec; _stscanf(charTime,charFormat,&nYear,&nMonth,&nDate,&nHour,&nMin,&nSec); CTime t(nYear,nMonth,nDate,nHour,nMin,nSec); CString s = t.Format(_T("%Y-%m-%d %H:%M:%S")); 含中文格式 要包含#include <locale.h> CString sTime = _T("2007-10-26 12:40:10"); TCHAR *charTime = (TCHAR*)(LPCTSTR)sTime; CString sFormat = _T("%d-%d-%d %d:%d:%d"); TCHAR *charFormat = (TCHAR*)(LPCTSTR)sFormat; int nYear; int nMonth; int nDate; int nHour; int nMin; int nSec; _stscanf(charTime,charFormat,&nYear,&nMonth,&nDate,&nHour,&nMin,&nSec); CTime t(nYear,nMonth,nDate,nHour,nMin,nSec); _tsetlocale(LC_ALL,_T("Chinese-simplified")); //本地化 CString s = t.Format(_T("%Y年%m月%d日%H时%M分%S秒")); |
摘:C++日期时间与字符串间的转换的更多相关文章
- Java开发笔记(四十四)本地日期时间与字符串的互相转换
之前介绍Calendar的时候,提到日历实例无法直接输出格式化后的时间字符串,必须先把Calendar类型转换成Date类型,再通过格式化工具SimpleDateFormat获得字符串.而日期时间的格 ...
- python 日期、时间处理,各种日期时间格式/字符串之间的相互转换究竟是怎样的?
模块函数说明 ''' date 日期对象,常用的属性有year,month,day time 时间对象,常用的属性有hour,minute,second,毫秒 datetime 日期时间对象,常用的属 ...
- c#日期与字符串间的转换(转)
1.日期转字符串(转载) 在编程中经常要用到将日期变量转换为字符串的情况,而且不同的时候希望转换成不同格式的字符串 下面是一些常用的转换及转换结果: (查看格式说明) 以日期为例: 2009-09-0 ...
- sql server日期时间转字符串
一.sql server日期时间函数Sql Server中的日期与时间函数 1. 当前系统日期.时间 select getdate() 2. dateadd 在向指定日期加上一段时间的基 ...
- sql server日期时间转字符串(转)
一.sql server日期时间函数Sql Server中的日期与时间函数 1. 当前系统日期.时间 select getdate() 2. dateadd 在向指定日期加上一段时间的基 ...
- sql server 日期时间与字符串的转换
一.sql server日期时间函数Sql Server中的日期与时间函数 1. 当前系统日期.时间 select getdate() 2. dateadd 在向指定日期加上一段时间的基 ...
- mysql日期/时间转换为字符串
将日期时间2016-05-13 16:07:50转化为字符串20160513 date_format select phone, date_format(time, '%Y%m%d%H%i%s') ...
- Java 日期时间与unix时间戳之间转换
日期时间 <--> 时间戳 java.time 包提供的新的日期和时间API LocalDateTime: 本地日期时间类 ZoneId: 时区类 ZonedDateTime: 带时区 ...
- 字符串类型日期时间转换为Date类型解析转换异常java.text.ParseException: Unparseable date: “2019-09-27T18:31:31+08:00”
错误的写法: SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //这里的格式也可以是别 ...
随机推荐
- 不错的VS2010扩展——JSEnhancements,让js和css也折叠
在Visaul Studio 2010中写js或css代码,缺少像写C#代码时的那种折叠功能,当代码比较多时,就很不方便. 今天发现,已经有VS2010扩展支持这个功能,它就是——JSEnhancem ...
- Altium Protel PCB Layer
The layers themselves are grouped by their functional types: Signal Layers – Top Layer, Bottom Layer ...
- NUMA架构
参考: http://www.ibm.com/developerworks/cn/linux/l-numa/ http://blog.sina.com.cn/s/blog_3f5c2f8c01000b ...
- git ssh key配置
原文:https://blog.csdn.net/lqlqlq007/article/details/78983879 git clone支持https和git(即ssh)两种方式下载源码: 当使用 ...
- tomcat JVM内存 配置
原文:http://elf8848.iteye.com/blog/467460 常见的内存溢出有以下两种: java.lang.OutOfMemoryError: PermGen space java ...
- 跨域策略文件crossdomain.xml
Web站点通过crossdomain.xml文件(放于站点根目录)配置提供允许的域跨域访问本域内容的权限 以土豆的为例: <cross-domain-policy> <allow-a ...
- Mysql -- 统计类用法
累加: update push_online a,(select msg_key, push_countfrom push_online)b set a.push_count=b.push_count ...
- 10.线程通信CountDownLatch
CountDownLatch 1.一个同步的辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个.多个线程去一直等待,用给定的计数.初始化“CountDownLatch”. 由于调用 count ...
- jQuery代码性能优化
代码优化是一个很重要的开发态度,一点点的优化对于程序来讲可能是微乎其微的,但是把所有的一点都加起来就能够达到水滴石穿的效果,所以要在平时的开发过程中养成优化代码的好习惯. 1. 检测元素是否存在 避免 ...
- POJ2528:Mayor's posters(线段树区间更新+离散化)
Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral electio ...