4 ms·
Sorry, was on mobile and didn't elaborate. Was referring to datetime.datetime.now(); why can't it incorporate the local timezone?
by macintux 5y ago
Sorry, was on mobile and didn't elaborate. Was referring to datetime.datetime.now(); why can't it incorporate the local timezone?
- Dunedan 5y agoWell, 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?