Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CTime.Format("%c") and COleDateTime problem

247 views
Skip to first unread message

Steve Villarreal

unread,
Feb 11, 2000, 3:00:00 AM2/11/00
to
I am trying to use either the CTime or the COleDateTime Format %c to
create a string with the date represented in the appropriate format for
the computer's locale. No matter what I have my system settings for
date format and for locale set to in the Regional Settings, the Format
returns mm/dd/yy. I noticed that there was a similiar question asked in
this forum back in December, but have not seen a response.

I have tried setting my clock back to 1999, and it works the same, so I
don't think it is Y2K related.

I am using VC++ 5.0 and get this response on both Windows 95 and NT 4.0.

Thanks for any help.

Steve Villarreal
steve.vi...@lennoxNOSPAMintl.com


Stefan Duffner

unread,
Feb 11, 2000, 3:00:00 AM2/11/00
to
Hi,
I don't know, if this is necessary, but I called setlocale(LC_TIME, "")
before the CTime.Format; and it worked (at least for %x und %X).
You have to include <locale.h>. I don't know if there is a MFC function
to set the locale, or if you need one at all.

Stefan

Steve Villarreal schrieb:

Kurt Santelé

unread,
Feb 11, 2000, 3:00:00 AM2/11/00
to
I had a simular problem.
I tried to format my date as dd/mm/yyyy but the month and day got reversed
everytime again.
And that was due to my (windows) settings. They were set as mm/dd/yyyy.
If I changed my settings to dd/mm/yyyy then my code worked fine.
If you try something like this, you will get the same result :
COleDateTime oleDate;
oleDate = COleDateTime::GetCurrentTime();
CString csDate = oleDate.Format(...);
oleDate.ParseDateTime(csDate);
csDate = oleDate.Format(...);
oleDate.ParseDateTime(csDate);
csDate = oleDate.Format(...);
oleDate.ParseDateTime(csDate);
Just parse the string and format it again. You will see that the date and
month get reversed.
That is if you format it NOT like in the settings !
I solved it by keeping the day, month, year, hour, minute and seconds
separately.
I know it's not a good solution, but it worked.
Creating a COleDateTime object can then be done like this :
COleDateTime oleDate;
oleDate.SetDateTime(...);

Hope it helps you out
Greetings
Kurt.S...@vartec.be


Steve Villarreal <randy....@attglobal.net> wrote in message
news:38A40A2F...@attglobal.net...

Scot T Brennecke

unread,
Feb 11, 2000, 3:00:00 AM2/11/00
to
Instead of the Format( "%c" ) version, have you tried the first version of the
Format function?:
CString Format( DWORD dwFlags = 0, LCID lcid = LANG_USER_DEFAULT );

You should be able to explicitly specify a locale ID, or let the
LANG_USER_DEFAULT locale be used.

0 new messages