[Interest] Relashionship between time_t and QDateTime

Thiago Macieira thiago.macieira at intel.com
Mon Aug 26 19:30:00 CEST 2013


On segunda-feira, 26 de agosto de 2013 17:42:58, Calogero Mauceri wrote:
> QDateTime myDateTime = QDateTime::fromTime_t(f_mtime);
> 
> The date time printed doing a myDateTime.toString() is
> 
>      Wed Dec 5 12:36:18 2007
> 
> 
> Retrieving the last modified information using QFileInfo, the result is
> different
> 
>      QFileInfo fi(filepath);
>      QDateTime myDateTime = fi.lastModified();
> 
> I get this result
> 
>      Wed Dec 5 11:36:18 2007
> 
> That is there is one hour difference. I guess the difference is due to
> the daylight saving management,
> but I can not understand how that management is performed.
> 
> Note: if I look at the file properties on Windows dialog, the last
> modified time is shown as
> 
>      Wed Dec 5 12:36:18 2007

Ah, Windows...

The problem might be simply a matter of timezones. The timestamps on files on 
Windows are not stored with time_t, but with some Windows-specific data. We get 
a FILETIME back from Win32.

Anyway, up until Qt 5.2, you cannot trust the output of a QDateTime with 
qDebug since it does not include the timezone. You have to ensure that the 
dates you're comparing by text are in the same timezone:

	qDebug() << dt.toUTC();

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130826/5b764798/attachment.sig>


More information about the Interest mailing list