The astimezone()
method shown by Paul will adjust the date and time to match the new timezone. This is usually what you want. For example, if the timestamp you have is UTC, and you want to convert it to UTC+1 (or any other timezone), then you need to add an hour (or do some other arithmetic), which astimezone()
does for you. It also takes care of daylight saving time or summer time, as well as numerous more substantial timezone irregularities.
However, sometimes this is not what you want. For example, if you have a UTC+1 timezone which is incorrectly labeled as UTC, then astimezone()
will add an hour, producing a UTC+2 datetime which is incorrectly labeled UTC+1. If that describes your problem, then you should use the replace()
method instead of astimezone()
. This will simply "relabel" the timezone without doing any conversion arithmetic. For example, it will convert 14:00 UTC to 14:00 UTC+1. This is most useful in cases where you have a timestamp with no timezone information, or a parser that isn't smart enough to understand the timezone information given.
(You need to know which of these two problems you have. It is not possible to automatically determine whether your datetime object has the "right" timezone information, because Python cannot guess your intentions.)