Hey Guys I have got a code which should compare the timestamps of my image files now I have got following code:
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")
If I execute it I code following values from the timestamp in the array, now I want to know rather, how I can change the value of 1900-01-01 09:02:05 to only 09:02:05 or I want to know how the value -2208956275 is generated from 1900-01-01 09:02:05
Thank you!
CodePudding user response:
To get string with only time from your Datetime object you can do something like this:
datetime.strftime(t1, "%H:%M:%S")
Timestamp is displayed as large negative number because it's in POSIX format which is seconds passed since 1970.01.01.