Python从系统(Ubuntu)读取本地时间并获得浮动格式

时间:2015-03-11 17:48:33

标签: python

我的问题很简单,我相信你可以提供帮助。我希望python从我的系统(Ubuntu)读取本地时间并转换为浮点数,例如如果时间是10:24:16,我希望得到它为10.4044。 python中有没有可以做到这一点的功能?

1 个答案:

答案 0 :(得分:1)

没有任何内置功能,因为这种特定格式并不是表示时间的常用方式。不过,构建自己的转换器真的很容易:

import time
def current_time_as_float():
    lt = time.localtime()
    return ((lt.tm_sec / 60.) + lt.tm_min / 60.) + lt.tm_hour