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秒")); |
相关文章
- 亲测:如何将Sat Mar 14 00:00:00 GMT+0800 (中国标准时间)转换成正常格式yy-MM-dd。字符串日期的比较compareTo方法。
- JS 时间字符串与时间戳之间的转换
- sqlserver 日期与字符串之间的转换 - youfeng
- SQLServer中日期与字符串之间的互相转换及日期格式
- Java将CST的时间字符串转换成需要的日期格式字符串
- python 日期、时间处理,各种日期时间格式/字符串之间的相互转换究竟是怎样的?
- Java8获取当前时间、新的时间日期类如Java8的LocalDate与Date相互转换、ZonedDateTime等常用操作包含多个使用示例、Java8时区ZoneId的使用方法、Java8时间字符串解析成类
- 将日期时间字符串转换为有效的日期值和有效时间值。
- C字符串和C++中string的区别 &&&&C++中int型与string型互相转换
- 二进制字节数组与十六进制字符串间的转换