如果你知道CString 的年月日的顺序
干脆用CTime的构造函数酸了
干脆用CTime的构造函数酸了
解决方案 »
- IOCP完成端口 WSAEnumNetworkEvents 函数 10038 错误
- 急!急!急!从LPCTSTR取出数据在线等答案
- 关于窗口位置
- 关于bmp图的问题?谢谢
- WTL的"CCommandBarCtrl"能不能在 "右键菜单" 和 "系统托盘菜单"中使用????? 如何使用????
- 在視圖上畫出的圖標有黑色的背景..
- smtp邮件发送服务器,的身份验证如何实现?
- 有没有一个比较方便的求指定目录下所有文件总数的方法
- 请教工具栏的问题
- 借宝地,打听一下:怎么检测计算机是否感染木马和终止木马程序的运行啊?
- 我想学习有关com和com+编程技术,不知选什么书籍作为入门
- AfxMessageBox在哪个.h文件中?
不好意思,没看过帮助有没有。
CString str;str.Formate("%s",ltime.Format("%Y-%m-%d %H:%M:%S"))
CString temptime; //以H:M:S形式表示的现在时间
timenow=CTime::GetCurrentTime();
temptime=timenow.Format("%H:%M:%S");
BOOL ParseDateTime( LPCTSTR lpszDate, DWORD dwFlags = 0, LCID lcid = LANG_USER_DEFAULT );
throw( CMemoryException );
throw( COleException );Return ValueNonzero if the string was successfully converted to a date/time value, otherwise 0.ParameterslpszDateA pointer to the null-terminated string which is to be parsed. For details, see Res.dwFlagsIndicates flags for locale settings and parsing. One or more of the following flags: LOCALE_NOUSEROVERRIDE Use the system default locale settings, rather than custom user settings.
VAR_TIMEVALUEONLY Ignore the date portion during parsing.
VAR_DATEVALUEONLY Ignore the time portion during parsing.
lcidIndicates locale ID to use for the conversion.ResCall this member function to parse a string to read a date/time value. If the string was successfully converted to a date/time value, the value of this COleDateTime object is set to that value and its status to valid.Note Year values must lie between 100 and 9999, inclusively.The lpszDate parameter can take a variety of formats. For example, the following strings contain acceptable date/time formats:"25 January 1996"
"8:30:00"
"20:30:00"
"January 25, 1996 8:30:00"
"8:30:00 Jan. 25, 1996"
"1/25/1996 8:30:00" // always specify the full year,
// even in a 'short date' formatNote that the locale ID will also affect whether the string format is acceptable for conversion to a date/time value.In the case of VAR_DATEVALUEONLY, the time value is set to time 0, or midnight. In the case of VAR_TIMEVALUEONLY, the date value is set to date 0, meaning 30 December 1899.If the string could not be converted to a date/time value or if there was a numerical overflow, the status of this COleDateTime object is invalid.If the string conversion failed due to memory allocation errors, this function throws a CMemoryException. In any other error state, this function throws a COleException.For a listing of locale ID values, see the sectionSupporting Multiple National Languages in the Win32 SDK OLE Programmer’s Reference.For more information about the bounds and implementation for COleDateTime values, see the articleDate and Time: Automation Support in Visual C++ Programmer’s Guide.
如有一CString str ="01 Nov 1999" 怎样将它转换成CTime?
time_t WantTime = t1.GetTime();WantTime为结果
char buff[5];
CString pStrTime;
pStrTime="1999-01-23";
int pYear,pMonth,pDay;
strncpy(buff,(LPCSTR)pStrTime,4);
pYear=atoi(buff);
strncpy(buff,(LPCSTR)pStrTime+5,2);
pMonth=atoi(buff); //如果你字符串日期 中的 月份是英文,就不能用这个,用条件来判断并转换成对应数字
strncpy(buff,(LPCSTR)pStrTime+8,2);
pDay=atoi(buff);pTime=new CTime(pYear,pMonth,pDay,0,0,0);如果还是不明白,写邮件告诉我,希望我能帮助你,我的邮箱:[email protected]