Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Behavior of datetime.datetime.strptime differs from documented behavior on %z #122781

Closed
Labels
extension-modulesC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@Thomasillo

Description

@Thomasillo

Bug report

Bug description:

importdatetimedatetime.datetime.strptime("2024-03-21T15:49:51",'%Y-%m-%dT%H:%M:%S%z')

will fail withValueError: time data '2024-03-21T15:49:51' does not match format '%Y-%m-%dT%H:%M:%S%z'

From the documentation forstrptime, empty string should be allowed here.

%zUTC offset in the form ±HHMM[SS[.ffffff]] (empty string if the object is naive).(empty), +0000, -0400, +1030, +063415, -030712.345216(6)

NB: strftime behaves correctly.

>>>datetime.datetime.strftime(datetime.datetime(2024,3,21,15,49,51),'%Y-%m-%dT%H:%M:%S%z')'2024-03-21T15:49:51'

Sostrptime(strftime(datetime.datetime(2024, 3, 21, 15, 49, 51), '%Y-%m-%dT%H:%M:%S%z'), '%Y-%m-%dT%H:%M:%S%z') would fail.

CPython 3.12.4, WSL2 (Ubuntu 20.04)

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp