加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – 参数必须是9项序列,而不是datetime.datetime

发布时间:2020-12-20 12:07:07 所属栏目:Python 来源:网络整理
导读:Web应用程序在以下行中突破; start_time = int(time.mktime(start)) * 1000 错误是TypeError – 参数必须是9项序列,而不是datetime.datetime 如何将datetime.datetime转换为9项序列? 解决方法 而不是传递datetime对象目录,使用 datetime.timetuple 方法: i
Web应用程序在以下行中突破;

start_time = int(time.mktime(start)) * 1000

错误是TypeError – 参数必须是9项序列,而不是datetime.datetime

如何将datetime.datetime转换为9项序列?

解决方法

而不是传递datetime对象目录,使用 datetime.timetuple方法:

>>> int(time.mktime(start)) * 1000
Traceback (most recent call last):
  File "<stdin>",line 1,in <module>
TypeError: argument must be 9-item sequence,not datetime.datetime

>>> int(time.mktime(start.timetuple())) * 1000
1406215043000L

顺便说一句,如果你使用Python 3.3,你不需要使用time.mktime.使用datetime.timestamp

>>> start.timestamp()
1406215043.0
>>> int(start.timestamp()) * 1000
1406215043000

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读