如何在Python中将ticks转换为datetime? [英] How to convert ticks to datetime in Python?

查看:1237
本文介绍了如何在Python中将ticks转换为datetime?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试将52707330000转换为1小时27分50秒。



不知何故在这里工作 - http://tickstodatetime.com/ 。我尝试检查该元素,但我不明白javascript。

解决方案

以下将将刻度转换为Python datetime对象从现在开始)使用datetime的timedelta。

  import datetime 
ticks = 52707330000
converted_ticks = datetime.datetime。 now()+ datetime.timedelta(microseconds = ticks / 10)

然后像:

  converted_ticks.strftime(%Y-%m-%d%H:%M:%S)//'2015-08 -07 14:17:48'

希望这有帮助!


$编辑:只使用 datetime.timedelta(microseconds = ticks / 10)将给你时间,而不是相对于now。


How to convert ticks to datetime in Python?

I am trying to convert 52707330000 to 1 hour and 27 minutes and 50 seconds.

Somehow it works here - http://tickstodatetime.com/. I tried inspecting the element but I don't understand javascript.

解决方案

The following will convert the ticks to a Python datetime object (from now) using datetime's timedelta.

import datetime
ticks = 52707330000
converted_ticks = datetime.datetime.now() + datetime.timedelta(microseconds = ticks/10)

Then something like:

converted_ticks.strftime("%Y-%m-%d %H:%M:%S") // '2015-08-07 14:17:48'

Hope this helps!

EDIT: Using just datetime.timedelta(microseconds = ticks/10) will give you the time, not relative to "now".

这篇关于如何在Python中将ticks转换为datetime?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆