VC时间字符串解析
求有没有解析时间字符串的专门的库
输入: 日期时间字符串和日期时间字符串格式
输出: 可以识别的时间类型(不限定,CTime time COLEDateTime都可以)
例如:
CTime GetTime(CString strTimeString,CString strTimeFormat);
mian()
{
CString strTimeString="2011/12/3";
CString strTimeFormat="yyyy/M/d";
CTime ct1=GetTime(CString strTimeString,CString strTimeFormat);
CString strTimeString="2011/12/3 8:9:10 am";
CString strTimeFormat="yyyy/M/d h:m:s A";
CTime ct1=GetTime(CString strTimeString,CString strTimeFormat);
}
[解决办法]
CTime::CTimeCTime( );CTime( const CTime& timeSrc );CTime( time_t time );CTime( int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec, int nDST = -1 );CTime( WORD wDosDate, WORD wDosTime, int nDST = -1 );CTime( const SYSTEMTIME& sysTime, int nDST = -1 );CTime( const FILETIME& fileTime, int nDST = -1 );
[解决办法]
#include <afxdisp.h>#include <stdio.h>COleDateTime t;int main(int argc, char **argv) { if (argc<2) { printf("Usage:%s \"DateTimeStr\"\n",argv[0]); return 2; } if (t.ParseDateTime(argv[1])) { printf("\"%s\" is a valid DateTimeStr.\n",argv[1]); printf("%s\n",t.Format("%Y-%m-%d %H:%M:%S")); return 0; } else { printf("\"%s\" is a INVALID DateTimeStr!\n",argv[1]); return 1; }}