# !/usr/bin/env python
# -*- coding: utf-8 -*-
# 存储待转换的时间
str_list = ['8d6h5m7s', '9d8h4m7s']
for str in str_list:
# t_dic用于存储d,h,m,s对应的值
t_dic = {'d': 0, 'h': 0, 'm': 0, 's': 0}
for t in 'dhms':
if str.find(t) != -1:
index = str.find(t)
t_dic[t] = str[0:index]
str = str[index + 1:]
print(t_dic)
uptime = int(t_dic['d']) * 24 * 60 * 60 + int(t_dic['h']) * 3600 + int(t_dic['m']) * 60 + int(t_dic['s'])
print(uptime)
记录时间格式dhms转成秒
最新推荐文章于 2024-10-20 19:21:40 发布