Parsing the MSVC++ predefined __DATE__
(maybe in conjunction with __TIME__
) macro with QDateTime::fromstring() returns nothing (= an invalid QDateTime object). Why?
From http://msdn.microsoft.com/en-us/library/b0084kay%28v=vs.80%29.aspx:
DATE The compilation date of the current source file. The date is a string literal of the form Mmm dd yyyy. The month name Mmm is the same as for dates generated by the library function asctime declared in TIME.H.
The dd
part seems to be filled with a leading space for days 1..9.
QtDateTime::fromstring() only supports
d the day as number without a leading zero (1 to 31)
dd the day as number with a leading zero (01 to 31)
One solution might be to remove duplicate spaces from the __DATE__
string prior to parsing, e.g. with QString::replace(" ", " ")
and parse the day with the single d
.
QLocale("en_US").toDate(QString(__DATE__).simplified(), "MMM d yyyy");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With