Reputation: 354
I'm converting a datetime.time
object's timezone to a different timezone. It looks like the easiest way is to create a datetime.datetime
from the datetime.time
object, then do the conversion.
Like this:
dt = datetime.datetime.combine(datetime.date.today(), self.data)
utc_dt = dt.astimezone(utc)
self.data = utc_dt.time()
Why doesn't datetime.time have astimezone like datetime.datetime does? It seems like that would make things much easier. Is it because timezone offset can be ambiguous without the date?
Upvotes: 1
Views: 732
Reputation: 1123440
Timezones require a date, the time alone is not enough.
That's because:
Upvotes: 7