开发者

getting the local system date time and converting it to a string (MFC C++)

I开发者_JS百科 have inherited some MFC C++ code (it's an ActiveX OCX control running on a Windows Mobile 6.5 device) and I need to acquire the system date and time and append it as part of an existing string which gets passed via the com port to another device.

I can get the system date and time, but I can not figure out how to convert that into a string so that I can append it (via strcat.)

I've found a number of different answers on Google and Bing for what at first glance seemed like such a simple problem... :( but I don't know enough MFC C++ to adapt any of it to my needs. Any help would be greatly appreciated.


CTime t = CTime::GetCurrentTime();
CString s = t.Format( "%A, %B %d, %Y" );
char * str = (LPCTSTR) s;

Note, I believe that str is only valid while s is in scope. Probably should copy it off somewhere if you need it to be around after s is destroyed. If you are passing it to strcat() you're probably OK.


In MFC the following code is for current date in MMDDYYYY format.

CTime t = CTime::GetCurrentTime();
CString strDate = t.Format("%m%d%Y");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜