PDA

View Full Version : fromMSecsSinceEpoch does not work as expected



nuliknol
27th January 2015, 18:43
Hi,

I have problems converting from timestamp to QDateTime. This is the code:



QDateTime somedate=QDateTime::fromMSecsSinceEpoch(1000*14220 21168);
QDate some_d=somedate.date();
qWarning() << "some_d=" << some_d.toString();


and this is what I get on the console:


some_d= "Mon Jan 5 1970"


The date I used is of 23 Jan of this year, as you can see below



-bash-3.00$ cat /tmp/test.php
<?
$ts=1422021168;
echo date("Y-m-d H:i",$ts);
?>
-bash-3.00$ /usr/bin/php -f /tmp/test.php
2015-01-23 07:52
-bash-3.00$


What I am missing?

TIA

Lesiok
27th January 2015, 19:12
Since multiply two int numbers result is an int and overflow. Change line to this :
QDateTime somedate=QDateTime::fromMSecsSinceEpoch((qint64)10 00*1422021168);

nuliknol
27th January 2015, 19:54
Since multiply two int numbers result is an int and overflow. Change line to this :
QDateTime somedate=QDateTime::fromMSecsSinceEpoch((qint64)10 00*1422021168);

wow! would never think that's the cause. Thanks a lot!

Lesiok
28th January 2015, 07:59
These are the basics of programming. Maybe first explore better C++.