2024-05-29 03:05:26 发布
网友
我对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
使用^{} class method:
>>> import datetime >>> mt = 1342993416.0 >>> datetime.datetime.fromtimestamp(mt) datetime.datetime(2012, 7, 22, 23, 43, 36)
然后使用^{} method格式化输出:
您也可以使用^{} function:
>>> import time >>> time.strftime(start_time_format, time.localtime(mt)) '2012-07-22 23:43:36'
使用^{} class method :
然后使用^{} method 格式化输出:
^{pr2}$您也可以使用^{} function :
相关问题 更多 >
编程相关推荐