julia - Julia函数将秒转换为小时、分钟、秒的问题
问题描述
我有这个代码让 Julia 将秒转换为小时、分钟和秒,但是当我运行它时,我只是得到(0, 0, 0)
输出。有人可以告诉我这有什么问题吗?
function convert_from_seconds(sec::Int64)
hours = 0
minutes = 0
seconds = 0
time = (hours, minutes, seconds)
if sec < 60
seconds = sec
elseif sec < 3600
minutes = floor(sec / 60)
seconds = sec % 60
elseif sec < 216000
hours = floor(sec / 3600)
minutes = floor(hours % 3600)
seconds = minutes % 60
end
return time
end
解决方案
这是您可能要考虑的另一种方法:
function convert_from_seconds(sec::Int)
x, seconds = divrem(sec, 60)
hours, minutes = divrem(x, 60)
hours, minutes, seconds
end
推荐阅读
- android - why is my Floating Action Button onclick not working?
- forms - Typo3 Fluid - 检查单选按钮是否被选中
- javascript - Webpack 自定义插件。使用 AST 在反应组件中插入属性
- java - 将 postgres 函数文件放在类路径中并在 Spring Boot 启动事件上执行,这是个好主意吗?
- javascript - 如何正确使用 flyTo() 和 setInterval() 或 setTimeout() Javascript 函数?
- regex - 正则表达式提取一个字符的第二个实例和另一个字符的第二个实例之间的字符串
- javascript - 从对象数组中删除键值
- linux - 是否可以挂载 FIT 映像中包含的文件系统?
- postgresql - 尝试将列类型从文本更改为几何时出错
- xpath - Google Sheets 表格格式中的 IMPORTXML XPath 问题