Results 1 to 4 of 4

Thread: fromMSecsSinceEpoch does not work as expected

  1. #1
    Join Date
    Apr 2014
    Posts
    53
    Thanks
    9

    Default fromMSecsSinceEpoch does not work as expected

    Hi,

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

    Qt Code:
    1. QDateTime somedate=QDateTime::fromMSecsSinceEpoch(1000*1422021168);
    2. QDate some_d=somedate.date();
    3. qWarning() << "some_d=" << some_d.toString();
    To copy to clipboard, switch view to plain text mode 

    and this is what I get on the console:
    Qt Code:
    1. some_d= "Mon Jan 5 1970"
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. -bash-3.00$ cat /tmp/test.php
    2. <?
    3. $ts=1422021168;
    4. echo date("Y-m-d H:i",$ts);
    5. ?>
    6. -bash-3.00$ /usr/bin/php -f /tmp/test.php
    7. 2015-01-23 07:52
    8. -bash-3.00$
    To copy to clipboard, switch view to plain text mode 

    What I am missing?

    TIA

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: fromMSecsSinceEpoch does not work as expected

    Since multiply two int numbers result is an int and overflow. Change line to this :
    Qt Code:
    1. QDateTime somedate=QDateTime::fromMSecsSinceEpoch((qint64)1000*1422021168);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Apr 2014
    Posts
    53
    Thanks
    9

    Default Re: fromMSecsSinceEpoch does not work as expected

    Quote Originally Posted by Lesiok View Post
    Since multiply two int numbers result is an int and overflow. Change line to this :
    Qt Code:
    1. QDateTime somedate=QDateTime::fromMSecsSinceEpoch((qint64)1000*1422021168);
    To copy to clipboard, switch view to plain text mode 
    wow! would never think that's the cause. Thanks a lot!

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: fromMSecsSinceEpoch does not work as expected

    These are the basics of programming. Maybe first explore better C++.

Similar Threads

  1. Event Filter doesnt work as expected
    By Hossein in forum Newbie
    Replies: 1
    Last Post: 12th July 2013, 21:01
  2. setFixedSize doesn't work as expected
    By jeremejevs in forum Qt Programming
    Replies: 2
    Last Post: 3rd June 2013, 08:50
  3. QDataStream doesn't work as expected
    By mastupristi in forum Qt Programming
    Replies: 1
    Last Post: 22nd June 2010, 07:08
  4. Replies: 9
    Last Post: 2nd December 2009, 18:59
  5. QHTTP::GET doesn't work as expected !
    By tuthmosis in forum Qt Programming
    Replies: 1
    Last Post: 27th July 2008, 15:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.