一个时间格式的输入结果

2024-05-29 03:05:26 发布

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

我对Python时间和日期时间方法非常困惑。有人能帮我吗?在

我只想实现从微时间浮点到格式字符串的转换:

mt = 1342993416.0
start_time_format = '%Y-%m-%d %H:%M:%S'

// Some time or datetime magic here..

OUTPUT >> The file's date is: 2012-07-23 19:00:00

Tags: or方法字符串formatoutputdatetimeheretime
1条回答
网友
1楼 · 发布于 2024-05-29 03:05:26

使用^{} class method

>>> import datetime
>>> mt = 1342993416.0
>>> datetime.datetime.fromtimestamp(mt)
datetime.datetime(2012, 7, 22, 23, 43, 36)

然后使用^{} method格式化输出:

^{pr2}$

您也可以使用^{} function

>>> import time
>>> time.strftime(start_time_format, time.localtime(mt))
'2012-07-22 23:43:36'

相关问题 更多 >

    热门问题