PDA

View Full Version : QDateTime to UTC string??



qtYoda
4th October 2014, 21:19
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.

anda_skoa
5th October 2014, 07:27
QDateTime::toUTC()?

Cheers,
_

qtYoda
6th October 2014, 14:22
Thanks. I misunderstood the documentation for fromMSecsSinceEpoch. I thought it set it to the UTC time since that's what it's receiving.