The function QDate::toString(const QString &format)
allows to display the month name with MMM
(eg 'Jan' to 'Dec') or MMMM
(eg 'January' to 'December').
But this function uses the system locale from QLocale::system()
( source code ).
What is the easiest way to display a QDate
with a month name, for a specific QLocale ?
You must use toString()
method of QLocale
instead of QDate
.
QDate d = QDate::currentDate();
QList<QLocale> locales {QLocale(QLocale::Spanish),
QLocale(QLocale::English),
QLocale(QLocale::Dutch),
QLocale(QLocale::Japanese),
QLocale(QLocale::French),
QLocale(QLocale::Chinese)};
QString format = "dd MMMM yyyy";
for(const QLocale locale: locales){
qDebug()<<locale.toString(d, format);
}
output:
"16 octubre 2017"
"16 October 2017"
"16 oktober 2017"
"16 10月 2017"
"16 octobre 2017"
"16 十月 2017"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.