4 ms·
Well, it can, it's just not the default: >>> from datetime import datetime, timezone >>> datetime.now(tz=timezone.utc).astimezone() datetime.dateti
by Dunedan 5y ago
Well, it can, it's just not the default:
>>> from datetime import datetime, timezone
>>> datetime.now(tz=timezone.utc).astimezone()
datetime.datetime(2021, 10, 25, 19, 58, 34, 51668, tzinfo=datetime.timezone(datetime.timedelta(seconds=7200), 'CEST'))
Or if you want to use a specific timezone:
>>> from datetime import datetime
>>> from zoneinfo import ZoneInfo
>>> datetime.now(tz=ZoneInfo("Europe/Berlin"))
datetime.datetime(2021, 10, 25, 19, 58, 34, 51668, tzinfo=zoneinfo.ZoneInfo(key='Europe/Berlin'))
- macintux 5y agoYes, but who’s more likely to get the code right to determine the system’s timezone: the programmer or the library? datetime.datetime.now() is by definition local to the system. What motivation is there to not include a timezone with the return value?