是否有Matlab函数将经过的秒数转换为HH:MM:SS格式? [英] Is there a Matlab function to convert elapsed seconds to HH:MM:SS format?

查看:365
本文介绍了是否有Matlab函数将经过的秒数转换为HH:MM:SS格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将经过的秒数转换为HH:MM:SS格式.是否有内置功能,还是我必须编写自己的功能?

I would like to convert an elapsed number of seconds into HH:MM:SS format. Is there a built-in function for this, or do I have to write my own?

推荐答案

datestr可能是您正在寻找的功能.将时间间隔表示为一天的小数部分,例如:

datestr is probably the function you are looking for. Express your time interval as a decimal fraction of a day, for example:

>> datestr(0.25, 'HH:MM:SS.FFF')

ans =

06:00:00.000    

也就是说,一天的四分之一是6个小时.如果要以这种方式转换间隔超过一天的时间,则必须调整第二个参数,以格式化函数的输出,例如:

That is, one quarter of a day is 6 hours. If you want to transform intervals longer than a day this way you'll have to adjust the second argument, which formats the function's output, for example:

>> datestr(2.256789741, 'DD:HH:MM:SS.FFF')

ans =

02:06:09:46.634

datestr的第一个参数也可以是日期向量日期字符串,而不是日期序列号.如果您有其他问题或编辑此问题,这应该可以帮助您入门.

The first argument to datestr could also be either a date vector or a date string rather than a date serial number. This should get you started, if you have problems ask another question or edit this one.

-
要使用datestr将时间转换为秒,请将该值除以24 * 60 * 60.

--
To convert a time in seconds using datestr, divide the value by 24*60*60.

示例:

t1 = toc;
timeString = datestr(t1/(24*60*60), 'DD:HH:MM:SS.FFF');

这篇关于是否有Matlab函数将经过的秒数转换为HH:MM:SS格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆