cygwin控制台中的Python datetime.now不正确 [英] Python datetime.now in cygwin console is incorrect

查看:132
本文介绍了cygwin控制台中的Python datetime.now不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您可以帮助我了解原因,请执行以下操作:从Cygwin终端:

If you could help me understand why: From Cygwin terminal:

这是正确的:

$ date
Wed, Sep  2, 2020 11:19:07 PM

这也是正确的:

$ date --utc
Wed, Sep  2, 2020  9:19:14 PM

时区也是正确的:

$ echo $TZ
Europe/Zurich

但是当从同一个Cygwin终端请求Python3中的本地时间时,它会显示以下内容:

But when ask for local time in Python3 from the same Cygwin terminal it shows this:

$ python
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import datetime
>>> datetime.now()
datetime.datetime(2020, 9, 2, 22, 20, 4, 339547)

小时不对吗?它显示为22h20m4s,但应为23h20h4s.

The hour is wrong? It shows 22h20m4s but it should be 23h20h4s as shown previously.

我想念什么?

谢谢

推荐答案

您正在使用Windows Python,而不是Cygwin.
cygwin与其他Cygwin程序相匹配

you are using Windows Python and not Cygwin one.
The cygwin one matches with the rest of Cygwin programs

$ python3
Python 3.8.3 (default, May 23 2020, 15:50:53)
[GCC 9.3.0] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> from datetime import datetime
>>> datetime.now()
datetime.datetime(2020, 9, 2, 23, 45, 26, 525415)
>>> quit()

 $ date
Wed, Sep  2, 2020 11:45:40 PM

这篇关于cygwin控制台中的Python datetime.now不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆