Question

I have a wxString which has a date as its value. The date format is stored depending on the regional setting or locale settings.

For eg. wxString dateStr = "9/10/2013" [dd/mm/yyyy format for Italy as regional locale setting].

When I parse the date string using wxDateTime::ParseDate(dateStr) and try to convert it in time_t using wxDateTime::GetTicks() function. But it swaps the value of day and month when the day is less than or equal to 12 for example 3/10/2013 or 12/11/2013. I am getting month as 3 and 12, and day as 10 and 11 respectively. But it works fine if the date is greater than 12 i.e 14/10/2013 or 28/10/2013.

I want to convert the above date string into time_t depending upon the locale setting. I am using windows as well as linux for development env.

Please help me out from this problem with an example or code snippet.

Was it helpful?

Solution

I suggest you use wxDateTime::ParseDateFormat instead, then you can specify the exact format of the date-string.

The reason you have problem with ParseDate is that it first tries to parse the date-string in American format (where the format is mm/dd/yyyy), and if it fails it tries other formats.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top