tags:

views:

511

answers:

1

Hi i try to get current time as timestamp without success here is my code that returnes me Sunday, January 25th 1970, 03:17:35 (GMT)

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

 return  QString::number(msecs);
+3  A: 

I think you are looking for this function:

http://doc.trolltech.com/4.6/qdatetime.html#toTime_t

uint QDateTime::toTime_t () const

Returns the datetime as the number of seconds that have passed since 1970-01-01T00:00:00, > Coordinated Universal Time (Qt::UTC).

On systems that do not support time zones, this function will behave as if local time were Qt::UTC.

See also setTime_t().

VestniK
i did that : QDateTime current = QDateTime::currentDateTime();uint timestame = current.toTime_t(); ,but it didnt gave me the current date after i tested the result here : http://www.4webhelp.net/us/timestamp.php
just tried pass string returned by QDateTime::currentDateTime().toTime_t() to this site and got correct time. Maybe you set wrong timezone in the form on this site.
VestniK