Question : How change format of date in MFC

Hi,

I am getting the current date in MFC application using the below code

SYSTEMTIME tm;
TCHAR date[32];
GetLocalTime(&tm);
GetDateFormat(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&tm,0,date,32);

format is : 08/19/2010. But i need to change the format like 08-19-2010. In C# i have the code like
string.format("MM-dd-yyyy",08/19/2010);

But in MFC what method and exact code writing to change. I am new in C++ and MFC. Please suggest me.Hope your's reply

Thanks

Answer : How change format of date in MFC

Have you seem the format string that can be passed?

http://msdn.microsoft.com/en-us/library/ms905235.aspx

int GetDateFormat(
  LCID Locale,
  DWORD dwFlags,
  CONST SYSTEMTIME* lpDate,
  LPCTSTR lpFormat,  <--------------- format string
  LPTSTR lpDateStr,
  int cchDate
);

lpFormat

[in] Pointer to a format picture string to use to form the date string. If lpFormat is NULL, the function uses the date format of the specified locale.
Use the following elements to construct a format picture string. If you use spaces to separate the elements in the format string, these spaces will appear in the same location in the output string. The letters must be in uppercase or lowercase as shown in the table (for example, "MM" not "mm"). Characters in the format string that are enclosed in single quotation marks will appear in the same location and unchanged in the output string.
Random Solutions  
 
programming4us programming4us