[Qt-interest] how to get datetime as milliseconds ?

Srdjan Todorovic todorovic.s at googlemail.com
Wed Apr 21 11:25:58 CEST 2010


Hi,

On 21 April 2010 10:09, Meir Yanovich <meiry242 at gmail.com> wrote:
> Hello
> i need to return current data+time as mili seconds since ( i guess 1970 is
> the default .. )
> i have the time_t that returns seconds , is there build in method for
> milliseconds ?

man 2 gettimeofday

That at least gives you microseconds, which you can convert to ms.

Or perhaps (not compile-tested):

QDateTime setTime = QDateTime::fromString (
QString("1970-07-18T14:15:09"), Qt::ISODate)
QDateTime current = QDateTime::currentDateTime();
uint msecs = setTime.time().msecsTo(current.time());

Or some other equivalent.

-Srdjan



More information about the Qt-interest-old mailing list