Results 1 to 4 of 4

Thread: How to convert unix time to QDateTime

  1. #1
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to convert unix time to QDateTime

    Hi,

    I have a unix time 1194278852, which is 11/05/2007 4:07pm GMT.

    How do I use Qt to convert it?

    Thanks

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to convert unix time to QDateTime

    Take a look at QDateTime (especially notice a static member it has).
    J-P Nurmi

  3. #3
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to convert unix time to QDateTime

    Quote Originally Posted by lni View Post
    Hi,

    I have a unix time 1194278852, which is 11/05/2007 4:07pm GMT.

    How do I use Qt to convert it?

    Thanks
    I did, I use QDateTime::fromTime_t and it is wrong. The other two does not even come close...

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to convert unix time to QDateTime

    Hmm... sounds fine to me:
    Qt Code:
    1. #include <QtCore>
    2. #include <QtDebug>
    3.  
    4. int main(){
    5. uint x = 1194278852;
    6. qDebug() << QDateTime::fromTime_t(x);
    7. return 0;
    8. }
    To copy to clipboard, switch view to plain text mode 

    $ ./x
    QDateTime("pon. lis 5 17:07:32 2007")
    The answer is in localtime which is GMT+1.

  5. The following user says thank you to wysota for this useful post:

    pdoria (23rd January 2008)

Similar Threads

  1. QDateTime GMT add sec. or - sec. from locale time....
    By patrik08 in forum Qt Programming
    Replies: 2
    Last Post: 20th February 2007, 16:39

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.