当前位置: 代码迷 >> 综合 >> 时分秒与时间戳相互转化(sys.argv)
  详细解决方案

时分秒与时间戳相互转化(sys.argv)

热度:112   发布时间:2023-10-08 16:25:35.0
import sys
# 把时分秒转化为时间戳
def countDown(time) :s = 0hour = time.split(':')[0]min = time.split(':')[1]sec = time.split(':')[2]s = int(hour) * 3600 + int(min) * 60 + int(sec)return s * 1000# 时间戳的只转为时分秒
def formatDuring(mss) :hours = int((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))minutes = int((mss % (1000 * 60 * 60)) / (1000 * 60))seconds = int((mss % (1000 * 60)) / 1000)if hours  < 10:hours =  '0' + str(hours)if minutes  < 10 :minutes = '0' + str(minutes)if seconds  < 10 :seconds = '0' + str(seconds)return str(hours) + ':' + str(minutes) + ':' + str(seconds)mss = sys.argv[1] # cmd下执行 python 文件名.py 参数1 参数2  sys.argv = [文件名.py,参数1,参数2]
if ":" in mss:print(countDown(str(mss)))
else:print(formatDuring(int(mss)))

时分秒与时间戳相互转化(sys.argv)

*******************************************************

时分秒与时间戳相互转化(sys.argv)

  相关解决方案