简体   繁体   English

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

[英]how do you convert current date time in NY time to epoch in python

I need to convert current date time to epoch time in python. 我需要将当前日期时间转换为python中的纪元时间。

I have tried this, but I am not sure is this tz="New_York/Americas". 我已经尝试过了,但是我不确定这是tz =“ New_York / Americas”。 Is below right? 在右下方吗?

import time

epoch_time = int(time.time())

You can use python's calendar module for this. 您可以为此使用python的日历模块。

from datetime import datetime
from calendar import timegm

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

For more, visit calendar's timegm . 有关更多信息,请访问calendar的timegm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM