Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #196292

Timezone in HH:MM Format

From "Ivan \"Rambius\" Ivanov" <rambiusparkisanius@gmail.com>
Newsgroups comp.lang.python
Subject Timezone in HH:MM Format
Date 2024-06-18 19:32 -0400
Message-ID <mailman.156.1718753550.2909.python-list@python.org> (permalink)
References <CAE9rwzP8rQe=-6b1jPdDr6rgG+fVztiQbQEWM5Z6Jhj44maNLw@mail.gmail.com>

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Timezone in HH:MM Format "Ivan \"Rambius\" Ivanov" <rambiusparkisanius@gmail.com> - 2024-06-18 19:32 -0400
  Re: Timezone in HH:MM Format Jon Ribbens <jon+usenet@unequivocal.eu> - 2024-06-19 00:12 +0000
    Re: Timezone in HH:MM Format "Ivan \"Rambius\" Ivanov" <rambiusparkisanius@gmail.com> - 2024-06-18 22:15 -0400

csiph-web