Issue
I'm sorry if this not the right place to post, but I have a large dataset of dates from a database, all of which are in the following format, localized to my timezone which is UTC +2:
2023-04-11 10:14:34+02:00
My question is, what is the usual convention: does the above date mean:
- in my timezone the hour for that date is
10:14:34
- in my timezone the hour is
12:14:34
? - in my timezone the hour is
8:14:34
?
From what I gather from the answer of xjcl here, the standard is to interpret my date as option 1). However, the function tz_localize' in python's pandas would convert the date above to 3), while pandas'
tz_convert` gives 1). So, which is the right way to interpret my date?
Solution
2023-04-11 10:14:34+02:00
is a date-time-offset string in ISO 8601 and RFC 3339 format, both of which prefer that the date and time components are separated with a letter T
, but permit using a space character instead (which is what you have).
In this format, the offset describes how the date and time values are related to UTC.
In your example, the date is 2023-04-11
, the time is 10:14:34
, and that point is two hours ahead of UTC. The corresponding UTC time would thus be two hours earlier, 8:14:34
.
None of this has anything to do with your local time zone. You can absolutely evaluate timestamps with a +02:00
offset regarless of whether your own local time zone offset is +02:00
or +05:30
or -08:00
, etc. Your local time zone is not relevant to the interpretation of the timestamp.
As for your question about the behavior of tz_localize
and tz_convert
, I suspect you are not considering at which point your datetime
values are "naive" and when they are "aware". Naive datetime
values in python don't contain any time zone information, thus if you convert them to "aware" values, then a conversion is going to be performed between two time zones - probably your local time zone and UTC. As to which direction the conversion happens depends very much on exactly what you do in your code (which you didn't supply in the question).
Answered By - Matt Johnson-Pint
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.