Python: what time zone is this specific time right now?

I have users from all time zones, and I want to send alerts at about 8 a.m. in each time zone of each user.

I need a python script that runs every hour [in the cron job], and I need to find out what time zone it is 8AM right now, and I can use this information to select users who should receive warnings.

How can i do this? It seems like gmt + 14 to gmt-12, which is 27 time zones, and there is only 24 hours a day!

+3
source share
2 answers

Python defines a tzinfo class that gives you the timezone offset, but does not provide a concrete implementation of the class. Several implementations are available, I have successfully used python-dateutil . Obviously, each user will need a time zone; for a one-hour (or half-hour) run, take the current UTC time and set its tzinfo member to the UTZ time zone; then use the function astimezoneto convert to each user time zone in turn and compare with some range around 8:00.

+1
source

, Newfoundland Time - UTC-3: 30. , . , , .. , 24 .

0

Source: https://habr.com/ru/post/1744995/


All Articles