Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
%I:%M%pで指定された入力があります(例: "6:02 PM")。私はこのコードに入力して、現在と当時の違いを見つけようとしています:
import datetime now = datetime.now() then = "6:02PM" tdelta = now - then
import datetime as dt now = dt.datetime.now() then = dt.datetime.combine(now, dt.datetime.strptime("6:02PM", "%I:%M%p").time()) print(then) # 2012-08-26 18:02:00 tdelta = now - then print(tdelta) # -1 day, 20:53:25.190721