Why this code return an invalid date?
QLocale locale("es");
QDate date = locale.toDate("1-Jun-14", "d-MMM-yy");
If debug the locale variable, it is initialized correctly to locale es_ES, but doesn't return the date and date.isValid()
returns false.
I don't know why but you have to put a
.
behind the month (short version). I tried the following code:The output was surprisingly:
Locks like a bug to me and fails if i try to use it with a e.g. german locale.
Update: Ok, i got it. This is pretty confusing. You have to take the short name given by
locale.monthName
. This is for e.g. "jun." for ES and "Juni" for DE. This does not really make any sense. In germany the short name for "Juni" is "Jun". For spain i do not know it. This is a bug.Update 2: I think i understand the system (at least for the german locale). If the full name is larger than 4 characters (e.g. "Januar") the short version is the real short form ("Jan") with a dot appended ("Jan."). If the full name is shorter than 4 characters the short form is exactly the same as the long form (e.g. "Mai"). But i do not get why a dot is appended, since for the EN locale no dot is appended.