简体   繁体   English

Python date.today显示第二天

[英]Python date.today shows the next day

I'm astounded by some code I wrote some time ago. 我对前段时间编写的一些代码感到震惊。 For not entering in much detail i have a method that runs through some objects, wich have a date parameter. 为了不进入很多细节,我有一个运行一些对象的方法,它有一个日期参数。 If the date parameter is equal to today's date, goes on. 如果date参数等于今天的日期,则继续。

I have set this in my local machine for test and have like 695 objects all with the same date, today, but when the action is run nothing happens, so i debug it to find that my expression date.today() returns datetime.date(2014, 3, 19) . 我已经在我的本地机器中进行了测试,并且今天有695个对象都具有相同的日期,但是当动作运行时没有任何反应,所以我调试它以找到我的表达式date.today()返回datetime.date(2014, 3, 19)

This is is incorrect, as the date of my computer from the date command is Tue Mar 18 20:56:09 AST 2014 . 这是不正确的,因为我的计算机date命令的dateTue Mar 18 20:56:09 AST 2014

I used from datetime import date . from datetime import date This is one of the more cryptic errors i have ever got. 这是我有过的一个比较神秘的错误。 Any experience someone can share here? 有人可以在这里分享经验吗? Thanks a lot. 非常感谢。

The method is not timezone aware and there's no platform-independent way to make it so. 该方法不是时区感知的,并且没有与平台无关的方法来实现它。 What is generally done is incorporate something like pytz and call .today() as: 通常做的是结合像pytz和call .today()这样的东西:

datetime.utcnow().replace(tzinfo = pytz.utc).strftime('%Y-%m-%d')

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

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