gpt4 book ai didi

python - 如何将纽约时间的当前日期时间转换为Python中的纪元

转载 作者:行者123 更新时间:2023-12-01 04:57:04 25 4
gpt4 key购买 nike

我需要在 python 中将当前日期时间转换为纪元时间。

我已经尝试过了,但我不确定这是否是 tz="New_York/Americas"。下面是对的吗?

import time

epoch_time = int(time.time())

最佳答案

您可以使用 python 的日历模块来实现此目的。

from datetime import datetime
from calendar import timegm

current_time = datetime.utcnow()
epoch_time = timegm(current_time.utctimetuple())

有关更多信息,请访问日历的 timegm .

关于python - 如何将纽约时间的当前日期时间转换为Python中的纪元,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27153375/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com