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


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

Re: Timezone in HH:MM Format

Started byMRAB <python@mrabarnett.plus.com>
First post2024-06-19 00:52 +0100
Last post2024-06-19 00:52 +0100
Articles 1 — 1 participant

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

  Re: Timezone in HH:MM Format MRAB <python@mrabarnett.plus.com> - 2024-06-19 00:52 +0100

#196293 — Re: Timezone in HH:MM Format

FromMRAB <python@mrabarnett.plus.com>
Date2024-06-19 00:52 +0100
SubjectRe: Timezone in HH:MM Format
Message-ID<mailman.157.1718754916.2909.python-list@python.org>
On 2024-06-19 00:32, Ivan "Rambius" Ivanov via Python-list 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
> 
Starting from Python 3.12, you can use "%:z" in the format string. For 
earlier versions of Python, you need to do some string slicing.

[toc] | [standalone]


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


csiph-web