- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下代码:
import time
from datetime import date, datetime, timedelta
def getNextDay(last_day):
#Returns tomorrows timestamp at two times: 00:00 and 23:59
last_day = datetime.utcfromtimestamp(last_day)
tomorrow = last_day + timedelta(days=1)
tomorrow_start = datetime(tomorrow.year, tomorrow.month, tomorrow.day, 0, 0, 0, 0)
tomorrow_end = datetime(tomorrow.year, tomorrow.month, tomorrow.day, 23, 59, 0, 0)
return [time.ctime(int(tomorrow_start.strftime("%s"))), time.ctime(int(tomorrow_end.strftime("%s")))]
last_day = 1370054073 #unix-timestamp
print "The day is:"
print time.ctime(last_day)
print "The next day is:"
print getNextDay(last_day)
当我运行它时,输出是:
The day is:
Fri May 31 23:34:33 2013
The next day is:
['Sun Jun 2 00:00:00 2013', 'Sun Jun 2 23:59:00 2013']
我找不到问题所在,因为 getNextDay()
函数似乎是正确的:我想从 1370054073
获取明天的 00:00 和 23:59。但它跳过一天,第二天的输出应该是 ['Sat Jun 1 00:00:00 2013', 'Sat Jun 1 23:59:00 2013']
有人可以告诉我哪里做错了吗?
最佳答案
来自 time.ctime
的文档:
Convert a time expressed in seconds since the epoch to a string representing local time. If
secs
is not provided orNone
, the current time as returned bytime()
is used.ctime(secs)
is equivalent toasctime(localtime(secs))
. Locale information is not used byctime()
.
因此,当您使用 print time.ctime(last_day)
时,您会看到基于本地时间的时间:
Fri May 31 23:34:33 2013
但是,当我使用它时,我看到了不同的时间:
Sat Jun 1 08:04:33 2013
您可以通过以下方式获取实际的UTC时间:
>>> datetime.utcfromtimestamp(last_day)
datetime.datetime(2013, 6, 1, 2, 34, 33)
而且,正如您所看到的,现在已经是 6 月 1 日
,因此您的函数运行正常,并且不会跳过任何天。
关于Python时间增量错误: skipping a day when trying to get tomorrow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36905256/
我正在寻找一种从接收日期的函数返回“明天”和“后天”的方法: 当前日期: "2015/04/24 18:15:00" future 的日期: "2015/04/25 02:40:00" 该函数应在此处
我看到了一些很奇怪的东西。 结果是 2013 年 10 月 9 日,星期三,这是正确的。 但是,这将导致 2013 年 10 月 11 日星期五。 它完全跳过星期四(实际上是明天)。 有任何想法吗
我知道这是一个有点具体的问题,但我已经遍历了 momentjs docs 的所有地方而且我一直无法找到一种方法来执行以下操作。 moment().fromString('tomorrow') // '
今天 2011 年 5 月 18 日如果我这样做 echo date("H:i m/d/Y", strtotime("tomorrow")); 我应该得到 00:00 05/19/2011 但如果我在
我安装了 Tomorrow theme使用 melpa 进入我的 Emacs24。 中文字符在评论中显示为块,而在其他地方显示正确的字符。 我的 .emacs 中的默认字体如下所示: (set-def
我有以下代码: import time from datetime import date, datetime, timedelta def getNextDay(last_day): #Re
我有一个 javascript 日期选择器,我正在更改他们在星期一、星期二等输入的日期。 我正在寻找一种简洁的方法来匹配明天字符串的任何部分,但至少要输入“tom”。 我想在用户键入时突出显示下一个日
仅使用标准 java 1.5 调用,我正在寻找一种简洁而简单的方法来获取特定时间的 java Date 对象,例如将来发生的下一个上午 10:30。通常是明天上午 10:30,但如果当前时间是上午 8
让我们以这个最小的例子为例: datetimepicker1 而JS代码是: var m = m
我正在使用 Bootstrap datepicker,以下是我的 jQuery 代码: $('.form_date').datetimepicker({ language: 'en',
$scope.date = new Date(); var tomorrow = new Date(); tomorrow.setDate(tomorrow.getDate() + 1); 我写过
我们使用 jqxgrid 在屏幕上显示房间信息。为了便于阅读,我们尝试将日期格式设置为“今天”或“明天”,而不是实际日期(今天或明天......)。 除了重新格式化为“今天”和“明天”之外,一切正常(
我有一个标签,它采用相对格式的日期,因此它会自动将今天和明天转换为“今天”/“明天”。我知道 UIDatePicker 有一个“今天”,但有什么方法可以让它说“明天”吗? 最佳答案 没有。那不是你可以
我正在使用 moment.js 来管理我的应用中的日期。但由于某些原因,日历并不总是显示预期的结果,有时我期待一个今天值,而我终于得到一个明天值(其他值似乎任何时候都是对的)。 作为函数中的入口值,我
我需要一个小脚本,但我有点困惑。 我想使用这个插件:http://keith-wood.name/countdown.html 目标:进行倒计时,从现在开始计算到上午 10:00 - 如果是上午 0-
已关闭。此问题旨在寻求有关书籍、工具、软件库等的建议。不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以
我想检查日期并以 4 格式获取结果 TheDayBeforeYesterday,Yesterady,Today,Tomorrow。 我有一个日期,我想将该日期与当前日期进行比较。 现在我已经这样做了,
我正在努力设置 NSDateFormatter 来解释日期,我想要一些简短但比 15/07/10 更直观的东西。我想我已经看到一些格式会简单地说“今天”或“明天”或同一周随后几天的星期几。是否有一种简
我想在我的主要 Activity 中添加一个函数,应用程序将获取设备时间。如果设备时间大于下午 2:00 或设备时间小于上午 08:00。启动屏幕后将显示一个弹出窗口“抱歉,时间已到,请明天上午 08
我找到了strftime 方法的格式指令列表http://ruby-doc.org/core-2.3.0/Time.html#method-i-strftime 有多种选项可以格式化时间,如工作日、月
我是一名优秀的程序员,十分优秀!