i'm lost with ParseDate and FormatDate (wx2.9)
Riccardo Cohen
rcohen at articque.com
Fri Feb 1 01:21:56 PST 2008
Hi
I don't know if I'm missing something, but it seems that ParseDate and
FormatDate do not work correcly together.
this is a sample code :
wxDateTime adate;
wxString tmpd=wxT("01/06/2000");
str+=wxString::Format(wxT("string is %s\n"),tmpd);
adate.ParseDate(tmpd);
str+=wxString::Format(wxT("Month is %d\n"),adate.GetMonth());
tmpd=adate.FormatDate();
str+=wxString::Format(wxT("Format is %s\n"),tmpd);
adate.ParseDate(tmpd);
str+=wxString::Format(wxT("Month is %d\n"),adate.GetMonth());
tmpd=adate.FormatDate();
str+=wxString::Format(wxT("Format is %s\n"),tmpd);
that produces :
string is 01/06/2000
Month is 0
Format is 06/01/2000
Month is 5
Format is 01/06/2000
The month and the day are exchanged
This does the same on windows and mac, and for locale french and english
I tried to use Format(wxT("%x")) and ParseFormat(wxT("%x")) :
tmpd=wxT("01/07/2000");
str+=wxString::Format(wxT("string is %s\n"),tmpd);
adate.ParseFormat((const wxChar *)tmpd,wxT("%x"));
str+=wxString::Format(wxT("Month is %d Year is
%d\n"),adate.GetMonth(),adate.GetYear());
tmpd=adate.Format(wxT("%x"));
str+=wxString::Format(wxT("Format is %s\n"),tmpd);
adate.ParseFormat((const wxChar *)tmpd,wxT("%x"));
str+=wxString::Format(wxT("Month is %d Year is
%d\n"),adate.GetMonth(),adate.GetYear());
tmpd=adate.Format(wxT("%x"));
str+=wxString::Format(wxT("Format is %s\n\n"),tmpd);
But there are many errors (see below). What is the best way to parse and
format date using locale settings ?
This is full result :
Results : FR WINDOWS
--------------------
ParseDate/FormatDate
string is 01/06/2000
Month is 0
Format is 06/01/2000
Month is 5
Format is 01/06/2000
===> #BAD exchange month and day
Parse %x/Format %x
string is 01/07/2000
Month is 6 Year is 2000
Format is 01/07/2000
Month is 6 Year is 2000
Format is 01/07/2000
===> OK
Results : GB WINDOWS
--------------------
ParseDate/FormatDate
string is 01/06/2000
Month is 0
Format is 06/01/2000
Month is 5
Format is 01/06/2000
===> #BAD exchange month and day
Parse %x/Format %x
string is 01/07/2000
Month is 6 Year is 2000
Format is 01/07/2000
Month is 6 Year is 2000
Format is 01/07/2000
===> #BAD month is the second numbe
Results : US WINDOWS
--------------------
ParseDate/FormatDate
string is 01/06/2000
Month is 0
Format is 1/6/2000
Month is 0
Format is 1/6/2000
===> OK
Parse %x/Format %x
string is 01/07/2000
Month is 0 Year is 2000
Format is 1/7/2000
Month is 0 Year is 2000
Format is 1/7/2000
===> OK
Results : FR MACOSX
--------------------
ParseDate/FormatDate
string is 01/06/2000
Month is 0
Format is 06.01.2000
Month is 5
Format is 01.06.2000
===> #BAD exchange month and day
Parse %x/Format %x
string is 01/07/2000
Month is 6 Year is 2020
Format is 01.07.2020
Month is 6 Year is 2020
Format is 01.07.2020
===> #BAD year not parsed correctly
Results : GB MACOSX
--------------------
ParseDate/FormatDate
string is 01/06/2000
Month is 0
Format is 06/01/2000
Month is 5
Format is 01/06/2000
===> #BAD exchange month and day
Parse %x/Format %x
string is 01/07/2000
Month is 6 Year is 2020
Format is 01/07/2020
Month is 6 Year is 2020
Format is 01/07/2020
===> #BAD year not parsed correctly and month is the second number
Results : US MACOSX
--------------------
ParseDate/FormatDate
string is 01/06/2000
Month is 0
Format is 01/06/2000
Month is 0
Format is 01/06/2000
===> OK
Parse %x/Format %x
string is 01/07/2000
Month is 6 Year is 2020
Format is 07/01/2020
Month is 0 Year is 2020
Format is 01/07/2020
===> #BAD year not parsed correctly and month/day exchange
Thanks for any help.
--
Très cordialement,
Riccardo Cohen
-------------------------------------------
Articque
http://www.articque.com
149 av Général de Gaulle
37230 Fondettes - France
tel : 02-47-49-90-49
fax : 02-47-49-91-49
More information about the wx-users
mailing list