Reputation: 2396
I would like to get a customized QDateTime such as:
QString string = "23 April 2012 at 22:51";
QString format = "d MMMM yyyy at hh:mm";
I am unable to as the literal at
is not recognized as an 'additional' string but has tokens associated.
a
-> AM or PMt
-> timezone information.Naturally I would take an approach such as an alternative:
QDateTime timeNow = QDateTime::currentDateTime();
QString time1Format = "d MMMM yyyy";
QString time2Format = "hh:mm";
QString time1 = timeNow.toString(time1Format);
QString time2 = timeNow.toString(time2Format);
QString timeConcat = QString(time1 + " at " + time2);
qDebug() << "Time = " << timeConcat;
How can I escape the 'at' keyword in my format?
ap or a Interpret as an AM/PM time. ap must be either "am" or "pm".
Upvotes: 1
Views: 1258
Reputation: 6074
You must enclose the at
string inside single quotes:
Any sequence of characters enclosed in single quotes will be included verbatim in the output string (stripped of the quotes), even if it contains formatting characters. Two consecutive single quotes ("''") are replaced by a single quote in the output. All other characters in the format string are included verbatim in the output string.
qDebug() << "Time = " << QDateTime::currentDateTime().toString("d MMMM yyyy 'at' hh::mm");
Upvotes: 6