在python中插入mysql表中的时间戳

2024-04-25 14:02:35 发布

您现在位置:Python中文网/ 问答频道 /正文

bidbest_bid_quantityfloatstarget_date在我的数据库中被设置为timestamp。在

获取时间戳

target_date_time_ms = (k.lastRestRequestTimestamp) 

base_datetime = datetime.datetime( 1970, 1, 1 )

delta = datetime.timedelta( 0, 0, 0, target_date_time_ms )

target_date = base_datetime + delta

时间戳=目标日期

^{pr2}$

错误-->


Tags: 数据库targetbasedatetimedatetime时间timestamp
1条回答
网友
1楼 · 发布于 2024-04-25 14:02:35

尝试使用time.strftime()

time.strftime('%Y-%m-%d %H:%M:%S', target_date.timetuple())

需要使用.timetuple()方法将target_datedatetime.datetime对象转换为time_struct结构,然后可以在对time.strftime的调用中使用该结构。在

相关问题 更多 >