Click to See Complete Forum and Search --> : Formatting date


eric33
May 28th, 1999, 06:40 AM
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

Franky Braem
May 28th, 1999, 07:15 AM
Have you changed your locale settings in Regional Settings ?

eric33
May 28th, 1999, 08:17 AM
Yes I have.
Therefore a customer test with england local settings and the problem is identical.

Note : The systems used are NT or w98.

May 28th, 1999, 08:24 AM
Can you not do

date.format(%d/%m/%y);

Franky Braem
May 28th, 1999, 08:51 AM
I've tested here at my portable. And I have the same problem.

Lee Marmara
May 28th, 1999, 09:48 AM
Try this.


COleDateTime timeNow;
timeNow = COleDateTime::GetCurrentTime();
CString strDate = timeNow.Format(VAR_DATEVALUEONLY);
CString strTime = timeNow.Format(VAR_TIMEVALUEONLY);

Roger Allen
May 28th, 1999, 11:21 AM
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

Robin Dunlop
June 22nd, 1999, 02:54 AM
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 );