Skip to content

datetime.strptime's %z should support +HH #128074

Open
@rubenbaer

Description

@rubenbaer

Feature or enhancement

Proposal:

The %z directive supports the UTC offset in the form ±HHMM[SS[.ffffff]]. Other parsing functions like fromisoformat on the other hand support the full format ±HH[MM[SS[.ffffff]]]. So there is no strptime format that supports the fromisoformat.

from datetime import datetime
datetime.fromisoformat("2023-05-25T15:35:05.666+01")  # ok
datetime.strptime("2023-05-25T15:35:05.666+01", "%Y-%m-%dT%H:%M:%S.%f%z")  # nok

The same may apply to %:z (#121237)

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-featureA feature request or enhancement

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions