Results 1 to 3 of 3

Thread: QDateTime to UTC string??

  1. #1
    Join Date
    Aug 2010
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default QDateTime to UTC string??

    I have a timestamp that was stored as QDateTime::currentMSecsSinceEpoch().

    I want to print the date/time but have it be in UTC so that it doesn't change based on timezone. What I was using (that isn't working) is

    QDateTime dt = QDateTime::fromMSecsSinceEpoch(myTimeStamp);
    QString dtS = dt.toString(QString("MMM d, yyyy @ h:m:s.zzz ap"));

    This string presents the timestamp in local time, not UTC. Is there a way to just get the string in GMT/UTC so that it presents a constant time regardless of where my users happen to be?

    Using Windows/Qt4.7.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QDateTime to UTC string??

    QDateTime::toUTC()?

    Cheers,
    _

  3. #3
    Join Date
    Aug 2010
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDateTime to UTC string??

    Thanks. I misunderstood the documentation for fromMSecsSinceEpoch. I thought it set it to the UTC time since that's what it's receiving.

Similar Threads

  1. QDateTime application level format string
    By davidovv in forum Qt Programming
    Replies: 12
    Last Post: 10th March 2013, 15:53
  2. Getting problems to convert from string to QDateTime
    By cesroc in forum Qt Programming
    Replies: 6
    Last Post: 2nd April 2012, 11:37
  3. std:string how to change into system:string?
    By yunpeng880 in forum Qt Programming
    Replies: 1
    Last Post: 14th April 2009, 08:51
  4. Replies: 1
    Last Post: 30th June 2006, 05:24
  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.