开发者

C++ MFC Get current date and time

I've been programming in VB.NET for most of my very programming career. I have a C++ project provided to me, which I need to make a few modifications, and I am feeling hopelessly lost and confused.

It is a Visual Studio 2008 MFC project in C++.

an output variable has been defined:

char szout[900];

This line below, is used to append values to the output variable before output:

strcpy(szout, "TextHere")

So one of the many examples from searching, that i have tried, was to include at the top:

#include <windows.h>

And then for my code:

SYSTEMTIME st;
GetSystemTime(&st);
char myDate[20] = st;
CT2CA outputDate(myDate);
strcat(szout, outputDate);

For some reason the variables appended on to szout must be of type CT2CA, which i'm not really sure what this is either.

But then I get the following errors on the second and third line (char myDate...etc...) and (CT2CA output....etc....)

error C2440: 'initializing' : cannot convert from 'SYSTEMTIME' to 'char [20]'

error C2664: 'ATL::CW2AEX<>::CW2AEX(LPCWSTR) throw(...)' : cannot convert parameter 1 from 'char [20]' to 'LPCWSTR'

So I'll clarify, I am a complete novice with this, and would开发者_运维知识库 appreciate any and all help.

Thank you,


If you are using MFC, why not:

// uses printf() format specifications for time
CString t = CTime::GetCurrentTime().Format("%H:%M");

// Or, if you have OLE Support
CString t = COleDateTime::GetCurrentTime().Format("%H:%M");


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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜