[Qt-interest] QDateTime daylight saving parsing time offset
Paul Drummond
paul.drummond at iode.co.uk
Wed Mar 30 17:21:16 CEST 2011
Thanks the detailed response Konrad - that clears it up for me.
Every time I come across a date/time issue like this I feel like I
have to take a day out to RTFM. I've read all the links mentioned
here (and more) various times before but it all leaves my head as soon
as I've finished the work. What's worse is the seemingly universal
assumption that date/time stuff is easy which is why I was given half
an hour to solve this problem this morning and no time to figure it
out properly!!
Anyway, thanks to all for the responses - I will try to digest this
stuff permanently this time!
Regards,
Paul Drummond.
On 30 March 2011 16:02, Konrad Rosenbaum <konrad at silmor.de> wrote:
> On Wed, March 30, 2011 14:52, Paul Drummond wrote:
>> For a project I am working on I get a date time string in the following
>> format:
>>
>> Tue, 29 Mar 2011 09:00:00 +0100
>>
>> Unless I'm mistaken (which happens a lot with me when working with
>> date/time conversions!) the above string is in UTC format. When
>> converted to a QDateTime the time should be 10:00:00, right? Or have
>> I got that completely wrong?
>
> It depends on whether you want the local time of where the string
> originated or UTC.
>
> If you want local time you just ignore the time zone spec (the "+0100").
> It tells you just how far the time stamp in removed from UTC
>
> If you want UTC you first get the local time and then _subtract_ the time
> zone spec (which has the format +/-hhmm or +/-hh).
>
>> I hate date/time hacking :-(
>
> Me too. But long long gone are the times (how ironic) when earth was
> flat... ;-)
>
>> In Java you can specify the offset using the "z" format specifier but
>> there is no format specifier for timezone in QDateTime unless I am
>> mistaken?
>
> QDateTime only understands UTC and local time and leaves all the
> arithmatic to the operating system.
>
>> I know QDateTime is supposed to handle daylight savings internally but
>> I'm still not sure what to do with the +0100. Is it okay to just
>> remove it from the string?
>
> As said above: if you want local time only - yes.
>
> If you are dealing with timestamps from many parts of the Internet and
> actually need to compare them you need an implementation of time stamps
> that can deal with this - Qt's can't, but if you can guarantee to have the
> offset it is trivial to wrap something around QDateTime.
>
> Little side hint: if the offset is missing from one of two timestamps you
> have a 14-hour(*) uncertainty interval on each side in which you cannot
> decide whether the time stamp is before or after the other one.
>
> (*)some time zones go beyond 12.
>
>
>
> Konrad
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
More information about the Qt-interest-old
mailing list