python - 如何让python显示当前时间(东部时间)

标签 python datetime time

如何让 Python 显示东部时间?

我查看了 python 文档,但它非常令人困惑。我正在使用 Python 3。

最佳答案

当然还有更直观的方法:

from datetime import datetime
from pytz import timezone
tz = timezone('EST')
datetime.now(tz) 
## this returns a datetime object pointing to right now 
## according to the timezone info object handed in as the tz variable. 

或者,您可以定义自己的 datetime 对象并将 tz 作为 tzinfo 传递,如下所示:

datetime(2016, 3, 30, 11, 13, 24, tzinfo=tz)

关于python - 如何让python显示当前时间(东部时间),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11710469/

相关文章:

javascript - 将 UTC 时间转换为十进制时间

java - 使用 Joda-Time 在 Java 中的 UTC 区域中的日期

python - 更改Python列表中的日期时间格式

java - 等待服务器给出的答复给定的时间

python - 使 FileChooserDialog 允许用户选择文件夹/目录

python - 在python中向列表实例添加一个方法

python - 在C中将Float转换为String,然后在Python中读取它

python - 在Python中比较时间序列中的字符串元素

time - 如何从 time::strftime 打印不带前导零的日期/时间?

c - 试图获取操作时间和接收时间 0 秒