-
Formatting date
I want to display date in local system format.
For example : dd/mm/yyyy for france and mm/dd/yyyy for us.
I try the following code but it didn't work :
CTime time = CTime::GetCurrentTime();
CString strDate = time.Format(_T("%x"));
In fact this code ALWAYS results in : mm/dd/yyyy
Please help
-
Re: Formatting date
Have you changed your locale settings in Regional Settings ?
-
Re: Formatting date
Yes I have.
Therefore a customer test with england local settings and the problem is identical.
Note : The systems used are NT or w98.
-
Re: Formatting date
Can you not do
date.format(%d/%m/%y);
-
Re: Formatting date
I've tested here at my portable. And I have the same problem.
-
Re: Formatting date
Try this.
COleDateTime timeNow;
timeNow = COleDateTime::GetCurrentTime();
CString strDate = timeNow.Format(VAR_DATEVALUEONLY);
CString strTime = timeNow.Format(VAR_TIMEVALUEONLY);
-
Re: Formatting date
Hi,
I think you may have to get around this problem by reading the settings from the registry used by the current user.
If you look at the key
[HKEY_CURRENT_USER\Control Panel\International]
The sub-key "sShortDate"="M/d/yyyy" tells you what format you would be required to display your date in. You would only have to parse this to get the information you need.
HTH
Roger Allen
-
Re: Formatting date
First of all: Skip CTime! COleDateTime will last for quite a while longer.
Then, formatting as regional settings can be done like this:
COleDateTime dt;
CString szDate;
szDate = dt.Format(VAR_DATEVALUEONLY , LANG_USER_DEFAULT);
// and the other way around
dt.ParseDateTime( szDate, VAR_DATEVALUEONLY, LANG_USER_DEFAULT );