はここに私のコードです:Pythonのdatetime型の変換
from datetime import datetime
def get_local_time(time_str):
"""
takes a string in the format of '27 March at 3:00' which is UTC
and converts it to local time and AM/PM
:param time_str:
"""
offset = datetime.now() - datetime.utcnow()
time_dt = datetime.strptime(time_str, '%d %b at %H:%M')
return (time_dt + offset).strftime('%I:%M %p')
私が唯一の時間だと日/月含まれていませんtime_strを使用しているとの問題を抱えています。すなわち: "2:00"
を、私はそれを変更する場合:time_dt = datetime.strptime(time_str、 '%のH:%のM')その後、私は1900年
前のstrftimeと年についてエラーが出ます私はここで困っている。入力文字列でちょうど時間を許すためには何が必要ですか?
これはうまくいくと思います。しかし、私は別のアプリ(Kodi)と一緒にこれを使用しています。そしてdateutilはライブラリに含まれていないようですので、動作しません。誰かが他に何かを持っていない限り、答えとしてマークしています。 – Bahnzo
@Bahnzo \tあなたがdateutilパッケージを望んでいない場合は、改善します。私には時間があります。 – MYGz
@Bahnzo \t私はそれが今あなたのために働くことを願っています。 – MYGz