dateTime.timestamp如何工作?

发布于 2025-01-28 07:38:00 字数 1197 浏览 2 评论 0原文

大家好,我有一个代码,该代码应该比较我的图像文件的时间戳,现在有以下代码:

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
enter image description here

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温暖的光 2025-02-04 07:38:00

要从DateTime对象中获取仅有时间的字符串,您可以执行类似的操作:

datetime.strftime(t1, "%H:%M:%S")

时间戳显示为大的负数,因为它是POSIX格式,该格式是自1970.01.01以来通过的秒。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文