Timezone in HH:MM Format

Liste des GroupesRevenir à cl python 
Sujet : Timezone in HH:MM Format
De : rambiusparkisanius (at) *nospam* gmail.com (Ivan \"Rambius\" Ivanov)
Groupes : comp.lang.python
Date : 19. Jun 2024, 00:32:17
Autres entêtes
Message-ID : <mailman.156.1718753550.2909.python-list@python.org>
References : 1
Hello,

How can I convert a date, usually datetime.now(), into a format where
the timezone is in hours:minutes format. I was able to get that format
in shell:

$ date +%Y-%m-%dT%H:%M:%S%:z
2024-06-18T19:24:09-04:00

The closest I got in python is

from datetime import datetime
from zoneinfo import ZoneInfo

s = datetime.strftime(datetime.now(ZoneInfo("America/New_York")),
"%Y-%m-%dT%H:%M:%S%z")
print(s)

This prints the same as the shell command above except the last column:
2024-06-18T19:28:56-0400

Any help will be appreciated.

Regards
Ivan

--
Tangra Mega Rock: http://www.radiotangra.com

Date Sujet#  Auteur
19 Jun 24 * Timezone in HH:MM Format3Ivan \"Rambius\" Ivanov
19 Jun 24 `* Re: Timezone in HH:MM Format2Jon Ribbens
19 Jun 24  `- Re: Timezone in HH:MM Format1Ivan \"Rambius\" Ivanov

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal