Results 1 to 4 of 4

Thread: Milliseconds from QDateTime

  1. #1
    Join Date
    Sep 2010
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question Milliseconds from QDateTime

    Hi, all
    I have code:
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QHBoxLayout>
    3. #include <QLabel>
    4. #include <QDateTime>
    5. #include <QString>
    6. #include <time.h>
    7.  
    8. int main(int argc, char *argv[])
    9. {
    10. QApplication a(argc, argv);
    11. QWidget* w =new QWidget;
    12. QHBoxLayout* lyaout = new QHBoxLayout;
    13. QLabel* label;
    14. time_t seconds;
    15.  
    16. QDateTime* date_f = new QDateTime;
    17. QString milisec;
    18. QString format="mmssz";
    19. QString & need_f=format;
    20. seconds=time(NULL);
    21. date_f->setTime_t(seconds);
    22. milisec=date_f->toString(need_f);
    23.  
    24. label = new QLabel(milisec);
    25. lyaout->addWidget(label);
    26.  
    27. w->setWindowTitle("Try again");
    28. w->setLayout(lyaout);
    29. w->show();
    30.  
    31. return a.exec();
    32. }
    To copy to clipboard, switch view to plain text mode 

    date_f->setTime_t(seconds) don't return time in milliseconds.
    Why is? What method can return time in milliseconds?

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: Milliseconds from QDateTime

    Miliseconds will always be zero here because time() has a resolution of one second.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2010
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Milliseconds from QDateTime

    I thought about it. Ok, what function can return time with milliseconds?
    My OS is Linux.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: Milliseconds from QDateTime

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QDateTime and comparsion
    By Talei in forum Newbie
    Replies: 0
    Last Post: 17th May 2010, 16:19
  2. QDateTime Invalid
    By FreePascal in forum Newbie
    Replies: 2
    Last Post: 7th June 2009, 19:35
  3. QDateTime problem
    By Majdi in forum Newbie
    Replies: 11
    Last Post: 28th January 2009, 15:57
  4. QDateTime fromString
    By mklieber in forum Qt Programming
    Replies: 1
    Last Post: 12th March 2008, 21:15
  5. QDateTime without Day
    By raphaelf in forum Qt Programming
    Replies: 4
    Last Post: 16th February 2006, 11:42

Tags for this Thread

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.