- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我是 python 的新手,正在尝试做一些看似微不足道的事情:我想将 if-not-modified header 添加到传递时间的 http 请求中,现在减去 60 秒。我在 now() - 60 秒部分遇到了很多困难。
我看过这个How do I convert local time to UTC in Python? , 这个How can I convert a datetime object to milliseconds since epoch (unix time) in Python? ,以及许多其他问题,但必须有比这种方法更直接的方法:
time.strftime("%Y-%m-%d %H:%M:%S",
time.gmtime(time.mktime(time.strptime("2008-09-17 14:04:00",
"%Y-%m-%d %H:%M:%S"))))
获取正确的时间并将其作为参数传递给 addheaders。
到目前为止,这是我的代码:
interval = 60 #changes other places
timestamp = datetime.datetime.now() - datetime.timedelta(seconds=interval)
opener.addheaders("if-modified-since", time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.gmtime(time.mktime(time.strptime(timestamp, "%Y-%m-%d %H:%M:%S")))))
它会抛出一个 TypeError: expected string or buffer
但总而言之,为了得到像 now() + 60 秒这样简单的东西,经过这么多的思考似乎是完全疯狂的UTC 字符串。有更多 python ninja-foo 的人可以帮我看看我的方法有什么错误吗?
最佳答案
datetime
有一个方法 utcnow
它以 UTC 而非本地时间返回当前时间,因此您可以将代码缩短为:
from datetime import datetime, timedelta
timestamp = datetime.utcnow() + timedelta(seconds=60)
opener.addheaders("if-modified-since", timestamp.strftime('%a, %d %b %Y %H:%M:%S GMT'))
关于python - addheaders if-modified-since 现在加上 60 秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17930157/
实例如下: ? 1
我正在我的网络应用程序过滤器中运行,该过滤器从外部源接收有关用户的信息,无论他是否登录。这是我的过滤器: @Override public void doFilter( ServletRequest
我从 apache.org 下载了 HttpComponents 库,并将 httpclient-4.3.5.jar 添加到了 Eclipse 项目中的库中。现在我尝试向 HttpPost 添加 he
是否可以使用 Response.AddHeader 特别是我正在尝试使用它的“刷新”。 我需要它在重定向之前暂停,但运行代码的位置在代码隐藏的 ASCX 中。当我的代码隐藏中有以下内容时,它什么都不做
有没有人向 ExpandableListActivity 添加静态 header 。请帮忙,我想在 ExpandableListActivity 中创建一个标题。谢谢深海 最佳答案 只需膨胀所需的 V
(因为这是我的第一个 SO 问题,我只想说我希望它不是太特定于 Zend。据我所知这应该不是问题。虽然我可以将它发布在Zend 特定的论坛,我觉得我至少有可能在这里得到一个好的答案,特别是因为答案可能
在使用拦截器和身份验证器添加访问 token header 时,当服务器以 401 响应时,我的身份验证器被正确调用。 Authenticator 通过单独的网络调用更新访问 token 并将其设置在
我们使用 ASP.Net 4.0。在我们的代码中,我们经常使用 Response.AddHeader("x", "y") .这和 Response.AppendHeader("x", "y") 完全一
我正在学习 Java 数据结构类(class),目前正在学习单链表。在addHead方法中,为什么我们需要检查tail == null?当 true 时,为什么 tail = head? public
在 C# Web 应用程序中,我使用 Response.Redirect("HR.aspx")并且它的工作没有问题。但是,当我尝试使用 Response.AddHeader("Refresh", "3
- (FMWebDAVRequest*) createDirectory { if (!_endSelector) { _endSelector = @selector(requestDidC
使用 Apache HttpClient 版本时: org.apache.httpcomponents httpclient 4.5.6 setHeader 和 addHe
我在页面上有一个 asp.net 超链接,单击它会在新窗口中打开一个新页面: lnkPrint.NavigateUrl = blah blah; lnkPrint.Target = "_blank";
本文整理了Java中org.apache.tomcat.websocket.WsWebSocketContainer.addHeader()方法的一些代码示例,展示了WsWebSocketContai
我知道这是一个愚蠢的问题,但我不是这方面的专家。 我正在关注教程 http://www.joshuawinn.com/fix-html5-validator-error-bad-value-x-ua-
我正在我的经典 ASP 页面 (vb) 上放置一个自动重定向。我想从变量 (url2) 调用 url 而不是对其进行硬编码。只需要知道正确的语法是什么。这是我当前的代码: Response.AddHe
我有一些代码,如下所示: public class EGOChervonAPIMethods extends HttpServlet { public void doPost(HttpServ
在我注意到我的代码可能在以经典模式设置的服务器上运行之前,我一直在使用 Response.Header.Add()。在这种情况下,异常“此操作需要 IIS 集成管道模式”。被提出。 我切换到 Resp
我是 python 的新手,正在尝试做一些看似微不足道的事情:我想将 if-not-modified header 添加到传递时间的 http 请求中,现在减去 60 秒。我在 now() - 60
我可以使用 setHeader 来设置新的标题吗? 还是我需要先addHeader,然后使用setHeader方法? 最佳答案 文档说您可以使用 addHeader 方法将多个值添加到特定 heade
我是一名优秀的程序员,十分优秀!