PDA

View Full Version : Why can I not generate a valid Time_t?



philwinder
11th March 2009, 14:01
Hi,
Using something like:

qDebug() << QString::number( QDateTime(QDate(11,3,9),QTime(13,59,30).toTime_t() );
looks nothing like a QDateTime::currentDateTime().toTime_t(), and when trying to convert it back to a QDateTime, does not retrieve the correct information. What am I doing wrong?

wysota
11th March 2009, 14:19
You want to see the time_t value for 9th March 11 at 13:59:30? You should get a highly negative value as time_t = 0 for 1st Jan 1970, about 1959 years after the date you set.

I guess you meant:

QDate(2009, 3, 11);

philwinder
11th March 2009, 16:19
Sorry, slight typo. However, replacing 09 with 2009 worked great. Thanks.