[SOLVED] Unable to convert string to int to perform MSecsSinceEpoch
-
Hello people!
I'm trying to convert a string into a date time format in the following way
@
QDateTime timestamp;
timestamp.setMSecsSinceEpoch(1350977160000);
qDebug()<< timestamp.toString(Qt::SystemLocaleLongDate);
@This works well and gives me the correct output as Tuesday, 23 October, 2012 12:56:00 PM
However, when I store 1350977160000 into a QString and then try to convert it to int , it doesn't seem to give the correct output. Instead, I get Tuesday, 05 February, 2013 5:30:00 AM@
QDateTime timestamp;
QString s = "1350977160000";bool ok; quint64 dateTime = s.toLong(&ok,10); timestamp.setMSecsSinceEpoch(dateTime); qDebug()<< timestamp.toString(Qt::SystemLocaleLongDate);
@
Please help me. Where am I going wrong?
Thanks. -
Try this,
@quint64 dateTime = Q_UINT64_C(1350977160000);@
or
Change this
@quint64 dateTime = s.toLong(&ok,10);@to
@double dateTime = s.toDouble();@
Hope it should work... :)
-
@
double dateTime = s.toDouble();
@This worked! I swear to God I tried this before but it didn't work. But it is now. Grrrr! Such a silly thing. Thank you very much Rochi :)
-
Your Welcome.. :)
[quote author="holygirl" date="1360042606"]@
I swear to God I tried this before but it didn't work. But it is now. [/quote]True... Sometimes it happens.... :)