PDA

View Full Version : Get English date format from in foreign locale



nhocjerry
1st October 2013, 12:21
I have a date string in English format as follow "05 May 2013", I used QDate::fromString to create a Date object from this string, but if I run my program in another PC which system locale is Germany the QDate::fromString can not parse the string because QDate::fromString will be localized according to the system's default locale settings.

So how can I set the English locale as default to get the correct date string in any PC with any system's default locale settings?

patrik08
1st October 2013, 15:04
try:

QLocale locale () const
void setLocale ( const QLocale & locale )
void unsetLocale ()

and after reset default locale...

anda_skoa
1st October 2013, 15:13
You have two options:

- You can change the locale for your program, see QLocale::setDefault().
- You can create a QLocale object for an English locale and use it to parse the date string, see QLocale::toDate()

I would suggest you do the latter.

Cheers,
_

nhocjerry
2nd October 2013, 04:30
Thanks all, it works perfectly :)