この動作は設計上の決定であったに違いありません。ここであなたがやりたいことをカスタマイズすることができ_strptime function in \Lib\_strptime.py
elif group_key == 'I':
hour = int(found_dict['I'])
ampm = found_dict.get('p', '').lower()
# If there was no AM/PM indicator, we'll treat this like AM
if ampm in ('', locale_time.am_pm[0]):
# We're in AM so the hour is correct unless we're
# looking at 12 midnight.
# 12 midnight == 12 AM == hour 0
if hour == 12:
hour = 0
elif ampm == locale_time.am_pm[1]:
# We're in PM so we need to add 12 to the hour unless
# we're looking at 12 noon.
# 12 noon == 12 PM == hour 12
if hour != 12:
の関連部分は、私はあなたが手足に出て行って、_strptime機能を再現することができ想像..
class foo(datetime.datetime):
"""foo(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])
The year, month and day arguments are required. tzinfo may be None, or an
instance of a tzinfo subclass. The remaining arguments may be ints.
"""
@classmethod
def strptime(cls, datestring, fmt):
if '%I' in fmt and not any(attr in datestring for attr
in ('AM', 'am', 'PM', 'pm')):
print('Ambiguous datestring with twelve hour format')
#raise ValueError('Ambiguous datestring with twelve hour format')
return super().strptime(datestring, fmt)
ですあなたの修正を加えて、それを適切に割り当てて、もう少しシームレスなものを作り出してください。しかし、それがどれほど賢明かはわかりません。それはpplがサルのパッチを当てるのですか?
@roganjosh私はそれを理解しています。私は心配していることをより明確にするように質問を更新しました。 – abc
'' 2017-07-04 12:24:11''には、AMかPMかを区別するのに十分な情報が含まれていません。私は十二時間のフォーマットのために何かにデフォルト設定しなければならないと思う。 – wwii
24時間形式の場合は "%H"を使用してください – ChristianFigueroa