python - 有人可以解释这个 python 代码的作用吗?
问题描述
我需要在 PHP 中创建这段代码,但我不知道 python,也不知道这段代码的作用。
import argparse
import codecs
import math
import os
import re
def leading_zeros(value, digits=2):
value = "000000" + str(value)
return value[-digits:]
def convert_time(raw_time):
if int(raw_time) == 0:
return "{}:{}:{},{}".format(0, 0, 0, 0)
ms = '000'
if len(raw_time) > 4:
ms = leading_zeros(int(raw_time[:-4]) % 1000, 3)
time_in_seconds = int(raw_time[:-7]) if len(raw_time) > 7 else 0
second = leading_zeros(time_in_seconds % 60)
minute = leading_zeros(int(math.floor(time_in_seconds / 60)) % 60)
hour = leading_zeros(int(math.floor(time_in_seconds / 3600)))
return "{}:{}:{},{}".format(hour, minute, second, ms)
例如,它将 926759167 转换为 00:01:32,675,但我不知道如何。
解决方案
它将自时间码 00:00:00,000 以来的微秒数转换为小时:分钟:秒,毫秒。毫秒被截断,而不是四舍五入。
推荐阅读
- php - PHP:尝试访问 bool 类型值的数组偏移量
- wordpress - WordPress 图片 URL 在 /wp-content 之前有一个空格
- nginx - Nginx:获取proxy_pass使用的上游URI
- apache-spark - Spark 结构化流式多种聚合选项
- java - 使用 indexOf、子字符串与模式匹配从核心 Java 中的网页中提取链接
- javascript - 在 Cypress 中测试复杂用户流程的最佳方法是什么?
- javascript - 我现在如何删除创建和附加的元素
- c# - 如何在 ASP.NET Core 3.1 中使用 protobuf-net 3
- python - 多次调用写函数但文本乱序(python)
- wordpress - Wordpress 在上传时自动缩放图像