[Python] How can I find the day of the week *adjusted for a timezone* using datetime (Python)?

Discussão em 'Python' iniciado por Stack, Setembro 25, 2024.

  1. Stack

    Stack Membro Participativo

    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.

    Continue reading...

Compartilhe esta Página