Python:PyDateTime_FromTimestamp 的用法
我正在开发一个 python c 扩展,并且想要创建一个带有 unix 时间戳的 python datetime 对象的实例。
在文档网站上 ( http://docs.python.org/c-api/datetime. html )我找到了函数 PyDateTime_FromTimestamp() ,它根据输入参数返回一个新引用。
描述如下: 创建并返回一个新的 datetime.datetime 对象,给定一个适合传递给 datetime.datetime.fromtimestamp() 的参数元组。
我尝试使用 PyFloat_Object 调用该函数,但该函数始终返回 NULL (甚至如果我简单地输入 0)。
有人有一个例子,我如何调用该函数,或者可以提示需要什么样的参数元组才能使其工作?
谢谢!
I'm working on a python c-extension and want to create an instance of python datetime object with a unix timestamp.
On the documentation site ( http://docs.python.org/c-api/datetime.html ) I found the function PyDateTime_FromTimestamp() which returns a new reference based on an input parameter.
The description is as follows:
Create and return a new datetime.datetime object given an argument tuple suitable for passing to datetime.datetime.fromtimestamp().
I tried out to call the function with a PyFloat_Object but the function always returns NULL (even if I simply put in 0).
Does somebody have an example how I have to call the function or can give a hint what kind of parameter tuple is required to get it work?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
谢谢伊格纳西奥!有时,小提示就能解决问题 - 这里是完整的工作示例:
Thank you Ignacio! Sometimes small hints make the solution - here the full working example: