I have this sql query:
SELECT LOG_TIME FROM PCY_LOG_EVENTS;
This returns data in the format \"DD-MMM-YY HH.MM.SS.MS\" like this:
Get the query value as a QString
QString dateTimeString = query.value(0).toString();
Then use the static fromString
function of the QDateTime
. You have to specify the format of your string. I assume the days of the month have a leading zero
QDateTime dateTime = QDateTime::fromString(dateTimeString, "dd-MMM-yy hh.mm.ss.zzz000000 A")
Notice the milliseconds part :zzz000000
. Since the max value can be 999 the trailing zeros of your example make no sense. So by using the zzz
followed by the zeros you can get the miliseconds stored in your string. The only possible problem is that your month part uses upper case letters while the MMM
returns the month abbreviation with just the first letter capitalized. I hope there won't be a problem with it.
Once you do the conversion you can easily get the milliseconds:
int ms = dateTime.time().msec();
For more formatting options here