Results 1 to 3 of 3

Thread: QDateTime::currentMSecsSinceEpoch ()

  1. #1
    Join Date
    Feb 2011
    Posts
    22
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default QDateTime::currentMSecsSinceEpoch ()

    Dear all,

    I would like your help concerning the current Date Time acquisition. I am trying to send a message from a client to a DB server. I am structuring the message as follows:

    Qt Code:
    1. int random = qrand() & 10000;
    2. QString message = QString("%1 J/N " + QDateTime::currentDateTime().toString()).arg(random);
    3. QByteArray msg = message.toUtf8();
    4. QByteArray data = "MESSAGE " + QByteArray::number(msg.size()) + " " + msg;
    To copy to clipboard, switch view to plain text mode 

    I have no error but the final output of the date time isn't like 0000-00-00 00:00:00 as i expected, but it looks like this the message "256 J/N Di 15. Mai 17:41:39 2012".
    Do you have any idea how to change it?

    Thank you in advance!

  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: QDateTime::currentMSecsSinceEpoch ()

    Why do you think it has to be 0000? QDateTime::currentDateTime returns you the current time.
    P.S.
    I think I understand. You mean the date format. If you want to have this result, regardless of the settings on your computer you must explicitly specify the format of toString.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QDateTime::currentMSecsSinceEpoch ()

    If you want the number of milliseconds since the epoch, as your thread title implies, then you should call QDateTime::currentMSecsSinceEpoch() to get a single massive number that has no format. If you want a portable string representation of the current time then I suggest you use:
    Qt Code:
    1. QString message = QString("%1 J/N %2").arg(random).arg(QDateTime::currentDateTimeUtc().toString(Qt::ISODate));
    To copy to clipboard, switch view to plain text mode 
    Note that I have use UTC to allow for time zone and daylight savings differences between client and server.

Similar Threads

  1. about QDateTime & timezone
    By lllturtle in forum Qt Programming
    Replies: 1
    Last Post: 2nd August 2011, 11:34
  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

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.