0

The datetime module allows for returning an integer representation of the weekday with:

weekday = dt.date.today().weekday()

However, this seems to be in UTC timezone (the default timezone for datetime). How can I convert this weekday integer to be adjusted for a timezone such as GMT? What I am looking for is something like the following using the pytz module:

weekday = dt.date.today().astimezone(pytz.gmt).weekday()

Is there an easy method of doing this so that the day reporting is accurate based on the shift in hours from the timezone? Thanks for any/all information.

  • 1
    try this link. https://pynative.com/python-timezone/ – Groot Aug 28 '22 at 05:33
  • Does this answer your question? [Display the time in a different time zone](https://stackoverflow.com/questions/1398674/display-the-time-in-a-different-time-zone) - Python 3.9+ [see this](https://stackoverflow.com/a/63628816/10197418) – FObersteiner Aug 28 '22 at 06:21
  • Btw. naive datetime represents *local time* in Python, i.e. in the time zone of the machine you run the script on. That might just happen to be UTC, but it doesn't have to. GMT ("Europe/London" tz) has zero UTC offset, so that might trick you into thinking it's UTC. – FObersteiner Aug 28 '22 at 06:23

0 Answers0