C++日期时间与字符串间的转换
来源:互联网 发布:有关网络犯罪的例子 编辑:程序博客网 时间:2024/06/05 01:55
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秒"));
- 日期时间与字符串间的转换
- 日期时间字符串与epoch的转换
- Java时间字符串与日期的转换
- C++日期时间与字符串间的转换
- C++日期时间与字符串间的转换
- C++日期时间与字符串间的转换
- c/c++日期时间处理与字符串string转换
- c时间日期与时间戳的转换
- golang日期字符串与时间戳转换
- 日期时间与字符串互相转换
- js转换时间戳与日期字符串
- 时间与日期的转换
- 时间与日期的转换
- c#日期与字符串间的转换
- c#日期与字符串间的转换
- Object-C日期时间与字符串的转化
- Object-C日期时间与字符串的转化
- mysql语法 字符串截取 日期时间与字符串转换
- LeetCode273Integer to English Words
- QT在子线程中使用QAxWidget需要初始化COM的问题
- OCR:Tesseract开源库介绍&字符识别方法
- finereport 详细设计
- 详解zabbix安装部署(Server端篇)
- C++日期时间与字符串间的转换
- tcpcopy 实践-引流到lvs(full-nat)
- 如何更改博客的名称
- 字符串内建函数format()
- Linux内核工程导论——进程:内核与用户空间的进程通信
- 使用dotween的sequnce动画
- BFS-hihoCoder-第六十六周-Have Lunch Together
- 查找gearman非法注册函数进程
- poj3040 贪心