View Full Version : QDate SystemLocaleShortDate without year

24th February 2010, 14:59
I'm using QDate.toString() to show a date for the user. Right now I'm using Qt::SystemLocaleShortDate to get a short date format with localization. It works perfect but I need the format without the year. Now it shows for example: "20.07.1969" I want only "20.07". Is this possible but still get it localized?

24th February 2010, 15:16
Have you see this http://doc.qt.nokia.com/4.6/qdate.html#toString?

24th February 2010, 15:27
Thanks! But will that take care of localization? For example if I use toString("dd.MM"), will that show dd/MM if in europe and MM/dd if in US?

24th February 2010, 19:17
I did not look the API very closely so next proposal might be a bit dumb but anyway it might be one way of doing what you want.

- Use QLocale::system().dateFormat(QLocale::ShortFormat) (http://doc.qt.nokia.com/latest/qlocale.html#dateFormat) to read the date format of the current locale
- Use QRegExp to remove year part and separator from the locale string (for example from "M/d/yy" --> "M/d")
- Use toString to format the date without year number

- Use QRegExp to remove year number and the separator that might be before or after the year in the string

Both of those will give you a localized date as you wanted, the "difficult" part is to figure out the correct regular expression to remove either the year number or yy from the string and the ./ or whatever separator character that might be before or after the year.

But as said, not the prettiest way of solving this issue, I indeed hope that there is some API method for this :)