Path: ...!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Jon Ribbens Newsgroups: comp.lang.python Subject: Re: Timezone in HH:MM Format Date: Wed, 19 Jun 2024 00:12:28 -0000 (UTC) Organization: A noiseless patient Spider Lines: 25 Message-ID: References: Injection-Date: Wed, 19 Jun 2024 02:12:29 +0200 (CEST) Injection-Info: dont-email.me; posting-host="19cf21608271e2dfc52f92be3ff6c24b"; logging-data="1689634"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/9rHb9Bs0qF3Kg/WEcxSoJfFbRSNJdFIs=" User-Agent: slrn/1.0.3 (Linux) Cancel-Lock: sha1:vYtZpaSEhmaZtcN4aYZucMPtJ8s= Bytes: 1692 On 2024-06-18, Ivan "Rambius" Ivanov wrote: > 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. datetime.now(ZoneInfo("America/New_York")).isoformat()