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


Groups > comp.lang.python > #196292 > unrolled thread

Timezone in HH:MM Format

Started by"Ivan \"Rambius\" Ivanov" <rambiusparkisanius@gmail.com>
First post2024-06-18 19:32 -0400
Last post2024-06-18 22:15 -0400
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  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

#196292 — Timezone in HH:MM Format

From"Ivan \"Rambius\" Ivanov" <rambiusparkisanius@gmail.com>
Date2024-06-18 19:32 -0400
SubjectTimezone in HH:MM Format
Message-ID<mailman.156.1718753550.2909.python-list@python.org>
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

[toc] | [next] | [standalone]


#196295

FromJon Ribbens <jon+usenet@unequivocal.eu>
Date2024-06-19 00:12 +0000
Message-ID<slrnv748jc.4u09.jon+usenet@raven.unequivocal.eu>
In reply to#196292
On 2024-06-18, Ivan "Rambius" Ivanov <rambiusparkisanius@gmail.com> 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()

[toc] | [prev] | [next] | [standalone]


#196296

From"Ivan \"Rambius\" Ivanov" <rambiusparkisanius@gmail.com>
Date2024-06-18 22:15 -0400
Message-ID<mailman.158.1718763340.2909.python-list@python.org>
In reply to#196295
Thank you all for your responses!

On Tue, Jun 18, 2024 at 9:54 PM Jon Ribbens via Python-list
<python-list@python.org> wrote:
>
> datetime.now(ZoneInfo("America/New_York")).isoformat()

Both .isoformat() and "%:z" work.


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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web