A QLocale
object can format dates and times, using the QLocale::toString()
methods that accept QDate
or QDateTime
.
Demo:
#include <QDate>
#include <QDebug>
#include <QLocale>
int main()
{
const QDate date{ 2017, 5, 5 };
const QLocale locales[]{ QLocale::English, QLocale::Chinese, QLocale::Finnish };
for (auto const& l: locales)
qDebug() << qPrintable(QString("In %0: %1 is %2")
.arg(l.nativeLanguageName(),
l.toString(date, QLocale::ShortFormat),
l.toString(date, "dddd")));
}
Output
In American English: 5/5/17 is Friday
In 简体中文: 2017/5/5 is 星期五
In suomi: 5.5.2017 is perjantaina
Short answer
You can write
QString week = QLocale{QLocale::English}.toString(date, "dddd");
(although I wouldn't call it week
- that makes me expect the week number within the year).