文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>python中时间字符串和秒数的相互转换

python中时间字符串和秒数的相互转换

时间:2008-11-25  来源:zpp71

1)秒数 ===》字符串

from time import *
 
def secs2str(secs):
        return strftime("%Y-%m-%d %H:%M:%S",localtime(secs))

 

2)字符串 ===》秒数

from time import *

先将时间字符串解析为9元组,例如:

2008-11-25 23:51:20,解析为9元组:[2008,11,25,23,51,20,0,0,0]。

>>> tmlist = [2008,11,25,23,51,20,0,0,0]

>>> mktime(tmlist)

1227628280.0

相关阅读 更多 +
排行榜 更多 +
别惹神枪手安卓版

别惹神枪手安卓版

冒险解谜 下载
坦克战争世界

坦克战争世界

模拟经营 下载
丛林反击战

丛林反击战

飞行射击 下载