dateTime.timestamp如何工作?
大家好,我有一个代码,该代码应该比较我的图像文件的时间戳,现在有以下代码:
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-01 09:02:05的值知道如何从1900-01-01 09:02:05产生-2208956275
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要从DateTime对象中获取仅有时间的字符串,您可以执行类似的操作:
时间戳显示为大的负数,因为它是POSIX格式,该格式是自1970.01.01以来通过的秒。
To get string with only time from your Datetime object you can do something like this:
Timestamp is displayed as large negative number because it's in POSIX format which is seconds passed since 1970.01.01.