嘿伙計們,我有一個代碼應該比較我的影像檔案的時間戳,現在我有以下代碼:
from datetime import datetime
import os
def gettime(folder_dir):
time_stamps = []
for images in os.listdir(folder_dir):
if images.endswith(".jpg"):
fn, fext = os.path.splitext(images)
# string name
timestamp1 = fn
# Convert String to datetime Object
t1 = datetime.strptime(timestamp1, "%H_%M_%S")
t1 = datetime.timestamp(t1)
# check if imgs have been taken in similar time (the seconds you want 1)
if len(time_stamps) == 0 or abs(int(t1) - min(time_stamps)) >= 11 or abs(int(t1) - max(time_stamps)) >= 11:
time_stamps.append(int(t1))
else:
os.remove(os.path.join(folder_dir, images))
gettime("Bilder")
如果我執行它,我會從陣列中的時間戳中撰寫以下值,現在我想知道如何將 1900-01-01 09:02:05 的值更改為僅 09:02:05 或者我想知道值 -2208956275 是如何從 1900-01-01 09:02:05 生成的

謝謝!
uj5u.com熱心網友回復:
要從 Datetime 物件中獲取僅包含時間的字串,您可以執行以下操作:
datetime.strftime(t1, "%H:%M:%S")
時間戳顯示為較大的負數,因為它采用 POSIX 格式,即自 1970.01.01 以來經過的秒數。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/472579.html
上一篇:如何更改基類成員的值?
